Brother we will not be held accountable for thoughts and fantasys etc as long as we do not act upon them or speak about them to others like friends etc. For Allah does not burden us with more than we can handle. Just try your best to block such thoughts and never speak about them nor act upon them. Stop thinking about it too much as dwelling on such things constantly will not help but make such an issue worse.
You will continue getting such images in your head as long as you keep looking at such images. So try your best to always keep your gaze low when you are out and not to look at any programs on TV, magazines billboards etc which have attractive women. It is simple the less you look at such images the less likely it is that you will have such images in your head. Images are not created by the brain but the brain uses the images that it has already stored to create other images and fantasys etc.
The following tips will help you inshallah:
10 Ways to resist sexual urges
1. If such a thought crosses your mind then just try and block it out by trying to remember Allah and recite: "Audhu billahi Minashaythanirajeem" or "La Hawla Wala Quwatha Illah billahill aliyil Adheem". Even if you get thoughts and fantasys then just think of Allah and the Prophet (Sallallahu Alaihi Wasallam) and that Allah is watching you at all times and this urge will go away.
2. Avoid being alone as much as possible. Shaythan plays with the minds of those who sit around idle and not doing anything. Find good company and stay in this good company. Spend time with your family and close ones (Not Non mahrams) Find good company and stay in this good company.The best company are those who lead you towards good and not those who lead you in the wrong direction. Don't hang around with those people who talk about sexual things and about girls and boys etc.
3. If you are associated with other persons having this same problem, you must break off their friendship. Never associate with other people having the same will quit together, you never will. You must get away from people of that kind. Just to be in their presence will keep your problem foremost in your mind. The problem must be taken out of your mind for that is where it really exists. Your mind must be on other and more wholesome things.
4. If these fantasys or thoughts come about at night whilst you are in bed then get out of bed and go into the kitchen and fix yourself a snack, even if it is in the middle of the night, and even if you are not hungry, and despite your fears of gaining weight. The purpose behind this suggestion is that you get your mind on something else. You are the subject of your thoughts, so to speak. If these thoughts come to you in the middle of the night then go and do wudu and pray Tahajjud and make much dua and cry in your dua's of Allah to increase you in imaan (Faith) and to help you resist your desires and to help you get married ASAP.
5. Find out when are your weakest times when your most likely to get these thoughts and fantasys and when you have established on what times and occassions this occurs then you can plan what to do to avoid feeling such temptations on those particular occassions.
6. Never read pornographic material especially on the internet as these images will be stored in your head and it will make your problem worse. Try to keep your gaze low at all times. Never read about your problem. Keep it out of mind. Remember --
"First a thought, then an act." The thought pattern must be changed. You must not allow this problem to remain in your mind. Don't keep thinking about it. Lern to ty and block it. If it comes ion your mind then just try to shrug it off by keeping yourself busy in a good act or accompanying good people or family etc. When you accomplish that, you soon will be free of the act inshallah.
7. Put wholesome thoughts into your mind at all times. Read good Islamic books, the life of the Prophet (Sallallahu Alaihi Wasallam) and his seerah, the life after death. There SO many interesting topics to read and learn about. Make a daily habit of reading at least one juz(Chapter) of Qur'an with its meanings.
Reading the Qur'an everyday with its meanings will bring countless blessings and rewards and bring you closer to Allah as well as keep you busy and occupied therefore keeping your mind off this problem.
8. Make much dua. But when you make dua don't just make dua about this problem, for that will tend to keep it in your mind more than ever. Make dua for increase of your iman(faith), Make dua for understanding of the Islam and the Qur'an, Make dua for your family and ALL Muslims especially the ones that are being oprressed, Pray for the sick and that we all unite as one. keep the problem out of your mind by not mentioning it ever --not in conversation with others, not inso much in your dua's. keep it out of your mind because if you keep mentioning it then it will stay in your mind!
9. Fast. You may have tried it before and it did'nt work but how can it work if we don't change our eating habits? If we eat little just to satisfy our stomachs then our fasting will be effective and restrict our sexual urges and capability's. But if we carry on over eating after our fasts then that food will impact on the stomach which will impact on our desires. So restrict the amount you eat before and after fasting and you will feel the benefits of fasting to stop your urges.
10. Finally the best solution of all- GET MARRIED. Give some urgency to your family about the need for you to get married sooner rather than later. Tell them of the benefits of getting married early and that it is a sunnah as the Prophet (Sallallahu Alaihi Wasallam) recommended it as it will help avoid haraam(Forbidden) relations with non mahrams and getting married early will help eradicate this problem and mean that one can indulge in their sexual urges and desires legitamatley as well as recieve reward for it. The main reason why there is so many haraam relations out there is for the fact that our families are not getting their children married early enough as the Prophet (Sallallahu Alaihi Wasallam) advised.
Hope that helped.