Teshuvah [repentance] is so great that it can convert sins [of the past] into merits (Yoma 86b).
Sins become merits only when the teshuvah is done out of an intense love for God.
This type of teshuvah is not the average kind of repentance, in which people regret having done wrong and commit themselves to avoid repeating the forbidden act. While that level of teshuvah is certainly commendable and indeed may suffice to eradicate a sin, it is not adequate to convert that sin into a merit. We may polish a pewter item to cleanse it of accumulated dirt, and even give it a luster, but it still will remain pewter. If we could find a way to convert pewter into gold, we would be changing its very essence.
In ancient history, some alchemists spent their entire lives trying to discover the magic formula that would enable them to convert base metals into gold. While this task remains impossible for metals, it is not impossible with human behavior. We can turn base acts into virtues. The "magic formula" is to develop so intimate a relationship with God that we not only regret having sinned, but feel the anguish of having displeased someone whom we love intensely.
Rabbi Levi Yitzchok of Berdichev once said to a person who was a known sinner: "How I envy you! When you will do teshuvah and convert your sins, you will have many more merits than I do."
Rather than allow the mistakes of the past to depress us, we should try to behave in such a way that we convert them into merits.