Sincere practice of worship to the creator and praying that you are given the knowledge of how to live a pure life, and really dedicating yourself to this path will teach you. One must dedicate their life to this, for it to work.

The real source of happiness is God, God’s love coming into us through our hearts. When we are not aware of this fully, our mind tries to find happiness outside ourselves, in the world. We must become aware of this through dedicated practice and actually finding it through experience, then living it. Then our energy will not want to go outside like this any more, because no reason will remain now that we have truly understood the reality.

Marriage without finding this truth is not a complete solution. Fasting without finding this truth is not a complete solution. Because in both scenarios, such desires as you mentioned will always be there, always be nagging you. Only through genuine understanding, the development of faith, the centering of your awareness to your heart (establishing here) that you will truly be able to be free of the temptations.

At the core of this all is the worship of God with genuine/sincere intention to reach God, experience God, be shown truth. Living with this intention with devotion will gradually turn all other things in your life to worship of God also. Never forget that when you practice fasting or other means of worship. The intention more than the activity itself is the most important. Everybody can go hungry for some hours or abstain from certain activities, or marry to have a partner. But will there be an actual change if there is not the right intention?

What I am speaking of is the true goal of all genuine religions, expressed in different words, but the desired experience in essence is the same.