Rav Chaim Palachi (a”h), in his sefer Chaim B’yad states that there is no need for one to be concerned about such dreams. On the contrary, the Gemara comments that certain dreams involving sinful conduct are actually auspicious signs. For example, the Gemara comments that one who dreams that he engaged in an incestuous relationship should expect to acquire wisdom and a dream of a relationship with a betrothed girl could mean that a person will become a Torah scholar. Clearly, then, a dream about an inappropriate act does not necessarily depict evil or indicate that one must repent.
However, the Ben Ish Chai (a”h), in his sefer Rav Pe’alim states that sometimes dreams of this nature may indeed be an indication that one had inadvertently sinned and requires atonement. He cites the Gemara’s comment in Masechet Nedarim that if a person dreamt that he was placed in excommunication, he should seek release from excommunication. Furthermore, Rav Chaim Palachi himself, elsewhere in his sefer states that it is praiseworthy to be concerned about such dreams. And he relates the story of the Tashbetz (Rabbi Shimon Ben Semah Duran of Algiers a”h) who dreamt that he ate non-kosher meat and after some inquiry discovered that indeed he had eaten some meat of questionable kosher status.
In fact, Rav Yaakov Chaim Sofer (a”h) would record every time he dreamt a bad dream and eventually collected all these descriptions into a special booklet. He writes that one year on Erev Pesach, he dreamt that some kosher meat and non-kosher became mixed together. He also dreamt that certain cheese which was assumed kosher was in fact not kosher. On other occasions, he dreamt that there worms in the bread sold in the kosher market, and that recently-slaughtered meat was not kosher.
Interestingly, in his sefer Kaf Ha’chaim, Rav Yaakov Chaim relates an incident of a person who entered the shul for Minchah and he began the service with the Amidah, skipping the preliminary recitations. He then dreamt a dream criticizing him for skipping these sections of the prayer service. As it turns out, this man was none other than the Kaf Ha’Chaim himself; he records this dream in the aforementioned booklet.
Thus, according to the Kaf Ha’Chaim, dreams of this nature are certainly worth concerning oneself about and one should respond through serious introspection and repentance.
Practically speaking, all this applies on the level of Midat Chasidut and is not required according to the strict Halachah. Additionally, one who feels distressed and anxious as a result of his dream should use it as an opportunity for introspection and teshuvah.