Someone said to the Beis Yisrael zt’l, “I have doubts in emuna, so what value can my tefillos have?”
The Beis Yisrael opened the Gemara where it says that when one says “Amen yehei shemei rabba..” with all his strength, even if he has thoughts of avodah zarah, he is forgiven.
“Do you see what is written here? The Gemara discusses a person who has thoughts of avodah zarah, yet even he can say “Amen yehei shmei rabba.”
So, no matter what level we fall to, we can daven and turn to Hashem.”

This even works if I had inappropriate thoughts when davening including them intruding into my mind during Nailah on Yom Kippur?