Assalamu alaykum wa rahmatullahi wa barakatuh
1) Stop listening to music.
2) Stop watching ANY kind of TV, movie etc. and throw away your TV, movies and music.
3) Remove pictures from your living place
4) Don't look/listen/touch at/to non-mahram women.
5) Don't have an idle mind/body, keep yourself doing something useful either worldly, religiously or both.
6) Do not entertain erotic thoughts, when they come, do dhikrullah. (Recite the Quran.)
7) Don't use the internet when you're idle, NEVER visit websites like y**t*be. (Not even for so-called 'Islamic' reasons, as it is a generally indecent place which most often suggests haram videos on sidebar.)
8) Don't use internet/computer when alone, use public computer.
9) Avoid bad company/bad friends, keep company with pious brothers. Avoid being alone for long time periods.
10) Do not read newspapers where you know that you will encounter indecent imagery. (There are plenty of ways of keeping yourself informed in a halal way.)
11) Do not eat spicy food
12) Do not sleep on your back neither on your stomach, sleep ONLY in sunnah way
13) DO MUCH DHIKR
14) DO MUCH DHIKR
15) DO MUCH DHIKR
Completely deactivating images in Firefox: Edit -> Preferences -> Content: Remove the check at "Loading Pictures Automatically".
(You might want to add exceptions for safe websites like Sunniforum.com or Askimam.org)
Completely deactivating flash: Uninstall the Flash Player (YES, it is possible to live without flash, there are plenty of people who enjoy the web without flash.)
Anyways, these are all only measures to prevent pulling the trigger of the urge.
In effect the above measures should be a standard, every Muslim should actually already have taken precautions because many things mentioned in the above are not permissible anyway.
But keep in mind: In the same way you are able to de-activate images/flash you are also able to activate them. The real reason which keeps you from doing the bad habit is to actually have strong iman. Strong iman is the only thing which keeps you from actually doing sin when being alone.
That is why you need to strengthen your iman by the will of Allah through dhikr; e.g. read Quran.
At some time, even with all these precautions the urge might nevertheless come up because it will be a simple waswasi proposal from Shaytan.
This is the point where the actual combat starts and it is won purely by your heart fearing Allah, doing dhikrullah and simply NOT doing it.
May Allah strengthen and guide you. Amin
Wassalamu alaykum wa rahmatullahi wa barakatuh