It is written that transgression extinguishes the light of a mitzva, but transgression does not extinguish Torah.
The light of the mitzva is like a candle that can be snuffed out, while Torah is a universal (spiritual) light that cannot be extinguished.
The mitzva, therefore, has to be watched over.
It needs to be "kept" as well as performed, lest there be some divergence or sin.
The mitzva, then, requires care. For, although the mitzva itself cannot be wiped out, the light that comes from it can be extinguished.
That is to say, in the balance between good and evil, the mitzvot themselves are not canceled out by sinful actions, as in a financial accounting of profit and loss.
They are two different categories independent of each other.
If a person has performed a mitzva, he gains a whole world.
His transgressions comprise another register of accounts and have no effect on the fact of the mitzva itself.
But the light that comes from the mitzva, the uplifting effect, is dampened, and even obliterated, by sin.
The conclusion to be drawn is that there is no arithmetic total of moral action.
There is only a sum of mitzvot and an adding up of transgressions, each in a separate category.
The evil does not cancel out the good, the good does not cancel out the evil.
The problem–if so it can be termed–is that of mutual encroachment and the tendency of sin to thrust the good aside with brutal disdain.
The advice of the Sages is to grab at the mitzva in all circumstances, never to be entirely overwhelmed by a wave of evil.
As a story about Rabbi Haim of Tsanz indicates:
A good woman was selling apples in the market.
A Cossack passed by and began to snatch at the apples and to fill his pouch.
The woman thereupon wailed aloud in helpless mortification.
The Rabbi, who happened to witness the incident, cried out, "Foolish woman, grab what you can of the apples just as he is doing!"
For although one may not always be able to restrain the wicked, that does not mean that I myself have to succumb and lose whatever chance I have for doing a mitzva.
If one were to wait for the evil impulse to leave one in a suitable frame of mind, one might well be deprived of most of the opportunities for good deeds.
Because the evil impulse changes its form constantly, its very nature is insidious.
It assumes a different aspect at every stage of life.
The idea is to be aware of it and to act accordingly.
–Rabbi Adin Steinsaltz
From "The Trials of Life" in The Candle of God by Rabbi Adin Steinsaltz