A mitzvah is a mitzvah, and a transgression is a transgression, and the one cannot be offset against the other.
A person cannot align his transgressions and mitzvot as two columns of figures that amount to a deficit or surplus of virtue.
Each occurs on a different plane and has its effect upon the person regardless of what transpires on the other plane.
A virtuous act does not reduce the negativity of a sinful act that preceded it, nor is it reduced by it.
So even the most wicked of the wicked, even a heretic or an apostate, is duty bound to fulfill every commandment of the Torah.
The fact that he is an unrepentant sinner who "even in his lifetime is regarded as dead" is true on one plane, and the fact that he is capable of performing mitzvot, and fully obligated to realize this capacity, is equally true on another plane.
Because that which is forbidden is, by definition, irretrievably bound to evil, its rectification and elevation can come about only with the destruction of evil in the messianic era, when God will transform the very nature of creation.
There is one exception to the rule that the positive essence buried within those objects and acts expressly forbidden by the Torah cannot be extracted by man.
The exception is teshuvah, "repentance" (literally, "return"), which, on its highest level, has the power to elevate elements that derive from the utterly profane kelipot to holiness.
–Rabbi Adin Steinsaltz
From Opening the Tanya by Rabbi Adin Steinsaltz