One of the things that we should keep in mind is that anytime we are allowing ungodly thoughts in our mind we are weakening spiritually/distancing further from Jesus. If we want to be successful in our walk with Christ we have to be intentional about what we choose to think on.
When ungodly thoughts try to come (i.e. thoughts of lust, jealousy, anger or etc) you must use scripture to fight against them. Also keeping your mind on Jesus throughout your day and meditating on scripture helps to keep those ungodly thoughts out! Remember that when our minds are idle satan will try to feed our minds with something evil.
For to be carnally minded is death; but to be spiritually minded is life and peace.