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. We ask Allaah to exalt his mention as well as that of his family and all his companions.
There is no doubt that residing in a non-Muslim country is a serious danger for the Muslim's religion, that's why the Prophet forbade Muslims from residing in a non-Muslim country. Therefore, your friend should be advised not to reside in that country, if there is no necessity or dire need for him to reside there, and to return to his country if it is a Muslim country. Anyway, he has to endeavour to reside with his wife in order to protect himself from committing adultery. However, if he is afflicted by residing in that country where he has no wife, we advise him to fear Allaah, lower his gaze and avoid going out to public places unless there is a need for it. He has also to cure what incites his desires by every permissible means, like fasting and practising sports and the like.
As regards masturbation, it is forbidden in principle, so he should not resort to masturbation. However, if he is obliged to repel his ardent desires and fears to commit adultery, then there is no doubt that masturbating is of a lesser degree of sinfulness than committing adultery. Yet, he is still sinful as this matter is not permissible Islamicly, but he did so to commit the lesser of two evils, and therefore he has to repent.
Allaah knows best.