Shmuel, again you raise some very good questions. There is an axiom which says, "What we resist, persists." The more effort you spend pushing away every obstacle and constantly thinking about how to avoid it, the more you will think about it and eventually act out.
that's why the trick is to accept the fact that there is Pritzus in the world and you have no power over controlling it. Hashem took away the Yetzer Horoh for Idol Worship but not for this. If he did, none of us would be born!!!!!
It's a good idea to read recovery books instead of thinking so much about how to avoid it. books by Rabbi Twersky like "Self Improvement? _ I'm Jewish is a good one. Also any books by Patrick Carnes.
You are right. Finding other things to occupy your time when you're bored, tired, hungry or upset is another key to staying clean. Pamper yourself with things which are permitted.
HOpe this helps. Keep up the good questions and your particular situations.