All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
In general, seeking knowledge is a kind of Jihaad (striving for the sake of Allaah). It is reported that Mu'aath Ibn Jabal said: "Seek knowledge, as learning the knowledge for the Sake of Allaah is achieving the fear of Allaah, and seeking it is an act of worship, and discussing it is Tasbeeh (i.e. glorifying Allaah), and looking for it is Jihaad." This statement is reported from him by Abu Nu'aym in his book entitled Al-Hilyah.
Religious knowledge is the first thing that is included in this, and this may include as well any beneficial knowledge which a Muslim learns in order to benefit his nation, like medicine and other sciences.
It appears from the question that you are referring to studying in non-Muslim countries, if this is the case, then it is not permissible to travel to non-Muslim countries if this study can be attained in Muslim countries, because there are many disadvantages on the person's religion when travelling to non-Muslim countries. For more benefit, please refer to Fataawa 84777 and 82091.
As regards the beard, it is forbidden to shave it and it is not permissible for a Muslim to travel to any country where he may be prevented from keeping his beard. However, as far as we know, there is no non-Muslim country that prevents Muslims from keeping their beard. If we presume that a Muslim has a sound reason for travelling to that country, and has a valid reason for shaving his beard, like in order to repel a real harm, and the like, then he is permitted to shave it only for a dire necessity. However, it should be noted that the permission of shaving the beard is within very restricted limitations, as there are many people who are scared without having a valid or a real reason, and then they build on this fear rulings and claim that they are in a necessity while in reality they are not. For more benefit, please refer to Fatwa 83699.
In the last part of your question, it might be that you are referring to the rule of committing the lesser of two evils in order to repel the greater evil; this is a confirmed rule with evidence. However, in order to apply this rule, one must consult the scholars as they are the ones who are capable of applying the rule to reality and find out whether or not there is really a contradiction between the two harms, and can decide which harm is greater than the other.