In order to be free from sexual immorality like lust and masturbation, you need to fight it and to flee from it.
"Flee from sexual immorality. All other sins a person commits are outside the body, but whoever sins sexually, sins against their own body. Do you not know that your bodies are temples of the Holy Spirit, who is in you, whom you have received from God? You are not your own; you were bought at a price. Therefore honor God with your bodies." (1 Corinthians 6:18-20)
What does fleeing mean?
It means you don't play with lusts. You run away from them.
1. Throw away any porn and any bad pictures in your home or phone/computer that has to do with lust.
2. Do not go to any place that might cause you to sin.
3. If you start thinking about lust, pray for God to help you overcome it. And do your part to fight against all these lustful thoughts. Don't fantasize about them.
God is the best and He has the best for you. No one and nothing can be compared with Him. God is the source of wisdom, joy, beauty, fun, power, love, goodness, creativity, and much more. He is the source of every good (James 1:17).
Psalm 16:11 says: “In Your presence is fullness of joy; in Your right hand there are pleasures forever”.
The pleasure of knowing God far exceeds the temptations of earth. Moreover, the pleasures on earth are nothing compared to the pleasures in heaven. God has created pleasures beyond earthly pleasures, because in His presence is fullness of joy and in His hand are pleasures forever.
Did you know you can have "exceeding joy" from knowing God (Psalm 43:4)?
So let us press on to know God. "The one who joins himself to the Lord is one spirit with Him" (1 Corinthians 6:17).
Flee from sexual immorality.
Do your part by being diligent to flee and fight hard against it. At the same time, rely on God to help you overcome it.
With your diligence and God's help, you can overcome any sin.