Remember that having such thoughts is not a sin. So Allah will not punish you for that. Some recommendations to help you with this thoughts:
1- Be in a state of Wudhu at all times, or as much as you can.
2- Whenever you have such thoughts, take deep breaths and say “La ilaha Illa Allah” 50-100 times. This will help a lot.
3- When such thoughts come to you, try to distract yourself. Do something. Watch something. Read something. Over time you will be able to control them Insha’Allah.
4- If there are certain situations that trigger these thoughts, try avoiding them.
5- Read these Du’as:
بِسْمِ اللَّهِ وَ بِاللَّهِ ، تَوَكَّلْتُ عَلَى اللَّهِ ، أَعُوذُ بِاللَّهِ السَّمِيعِ الْعَلِيمِ مِنَ الشَّيْطَانِ الرَّجِيمِ
And this one:
بسم الله و بالله محمد رسول الله ، و لا حول و لا قوة إلا بالله العلي العظيم
And this one:
اللّهُمَّ إِنِّي أَعُوذُ بِكَ مِنَ الكَسَلِ وَالفَشَلِ وَالهَمِّ وَالجُبْنِ وَالبُخْلِ وَالغَفْلَةِ وَالقَسْوَةِ وَالمَسْكَنَةِ وَالفَقْرِ وَالفاقَةِ وَكُلِّ بَلِيَّةٍ، وَالفَواحِشِ ما ظَهَرَ مِنْها وَما بَطَنَ، وَأَعُوذُ بِكَ مِنْ نَفْسٍ لا تَقْنَعُ، وَبَطْنٍ لا يَشْبَعُ، وَقَلْبٍ لا يَخْشَعُ، وَدُعاءٍ لا يُسْمَعُ، وَعَمَلٍ لا يَنْفَعُ، وَأَعُوذُ بِكَ يارَبِّ عَلى نَفْسِي وَدِينِي وَمالِي وَعَلى جَمِيعِ مارَزَقْتَنِي مِنَ الشَّيْطانِ الرَّجِيمِ، إِنَّكَ أَنْتَ السَّمِيعُ العَلِيمُ.
6- Pray the Night Prayer (if you can all 11 Rak’as)
7- Avoid sins as much as possible. The more we avoid sins, the purer our souls and hearts become, and the more we are able to resists such thoughts.
May Allah bless you