Read alot of scripture, then meditate upon it.
The mind is complex and forms associations with the things we allow to be put into it. When you input scripture, you will form new associations, and establish new thought patterns.
Also, retrain your mind as per Philippians 4:8. Choose to think about good things. This will involve taking thoughts captive as per 2 Corinthians 10:5.
As you begin to practice these things, you will find both your heart and mind stayed more and more upon the Lord.