I know exactly what you're talking about. I've made mistakes in the past that sometimes haunt me.
However, the best way to get it off of my mind is to understand that the past is the past and there is nothing you can do about it. The future is what lays ahead. Make the best of it without dwelling on the past.