Rabbi Samson Raphael Hirsch wrote that even the most depressing awareness of having committed wrong need not irredeemably rob you of good spirits. Once you recognize your wrong deed, do not cover it up and let it gnaw at you. Rather view your act in a clear light, admit it to yourself and before the Almighty, and try to make up for it as best as possible.
Before the Almighty, earnestly promise to avoid such harmful acts in the future. From this determination, you can regain the serenity which is essential to fulfilling your goals and responsibilities.