B"H
The Rambam in the laws of Teshuva as you cited indeed says that a tzadik is one who has a majority of merits, a wicked person is one who has a majority of not good deeds (which the Rambam says would cause one to pass away instantly G-d forbid) and an average person (beinoni) is one who has half righteous deeds and half wicked deeds.
To clarify, "majority" does not mean 51% deeds in quantity alone, the Rambam says that there can be one good deed worth many bad deeds etc... So it's a combination of quantity and quality.
But does this measurement apply even after one does Teshuva? The Gemara says that when one does Teshuva one's bad deeds are converted to good deeds, so is one still considered to "have" those bad deeds after doing Teshuva?
Also, a source in the Gemara says that if one transgresses even one prohibition, even a seemingly "minor" rabbinic prohibition, is called "wicked", and one who does Teshuva is called "completely righteous", so how could we ever have a middle state of a "beinoni", an average person, who has half righteous deeds and half wicked deeds (seemingly, before even doing Teshuva)? If he didn't do Teshuva, then he would be completely wicked for even one minor misdeed, and definitely for not performing a mitzvahs aseih.
Based on these questions, and other sources, the Tanya chapter 1 concludes that when the Rambam says that a righteous person is one who has a majority of good deeds (seemingly, even before doing Teshuva, according to my understanding, although correct me if I'm wrong), he's only "righteous" in a figurative, non literal sense, of still being able to live, meaning that he is meritorious in his divine judgement passed against him, which happens every moment.
Then he says that there's actually a "true" understanding of a righteous person, which is a completely different category than that the Rambam mentions, which is one who has no yester hara at all (OR has it not it's completely inoperable).
He quotes the Gemara and Rashi which references the verse from King David "my heart is empty within me", that through fasting, King David "killed" his yeitzer hara.
Then he quoted a midrash as saying that Hashem saw that the righteous were few, so he scattered the souls of the righteous throughout many generations, only having a few alive at any given time.
This does not have anything to do with the free choice one has in one's actions of thought, speech and deeds, which are in one's control, which determine if one is the "figurative"/"borrowed term" of a righteous person that the Rambam talks about, this is only referring to certain souls having the ability within them to completely banish/transform the yeitzer hara within oneself, while other people who weren't created with those few souls don't have that ability to transform their inner nature, and perhaps the entire purpose of their existence is to be in a constant inner battle etc. until moshiach comes.
To summarize, according to Tanya:
In the realm of the "borrowed" terms of righteous, average, and wicked (although the Tanya doesn't explicitly say that the term "wicked" is also a borrowed term I'm assuming it is based on the context):
When the Rambam says that a righteous person has a majority of good deeds, implying he could still have even one minor bad deed, that's just a borrowed term.
Similarly, an average person who has half bad deeds and half good, is still a borrowed term.
A wicked person is one who has a majority of bad deeds (and again, majority in this context is not only quantity but mainly quality), and the Rambam says if one reaches this level G-d forbid, they would instantly pass away.
According to the Rambam (and my understanding of the sources), all of these cases must be talking about before one has done (complete) Teshuva, because of one has done complete Teshuva, then one would not have even one minor bad deed remaining. (Again this is my own understanding not explicitly mentioned in Tanya but I think this is the only way to understand it).
Now, in the more "real" terminology of wicked, anyone with only one minute prohibition in their "list" of deeds is considered wicked. Even a rabbinic prohibition, and for sure a nullification of a positive commandment of the Torah, even the commandment to consistently be involved in Torah study every second.
Later in Tanya it classifies your even further and says even if one intentionally has bad thoughts once in every few years, one is classified as wicked (until one has done Teshuva, seemingly).
If one has done Teshuva, then one has no bad deeds in their accounting at all, so they are not wicked. But if so, what are they (according to the "real" terminology)?
Even if one has done complete Teshuva, they are either a tzadik or an average person.
The difference between the two, according to Tanya, is not based on one's deeds at all, but only based on one's internal nature that only Hashem decided at the time of one's birth, like it says in Job, "you have created righteous (souls)".
Either one was created with a soul that has the ability to transform/nullify the yeitzer hara completely, or one was not.
If one was, and one accomplished that, then one is a "true" tzadik (and within that itself, there are many different levels, depending on if it is completely transformed or only "dormant" but has no actual effect).
If one was not, AND if one has no bad deeds at all currently (either through doing Teshuva for past deeds or if one has never done any prohibition in their entire life), then one is "average", according to the "true" definition.
This, the Tanya says, is why Rabbah in the Gemara made the mistake about himself to think he was an average person, despite the fact that his mouth never ceased from words of Torah, implying that he didn't even nullify any positive commandment, and for sure he didn't violate any negative rabbinic or Torah commandments.
Because if Rabbah, when saying he was average, meant only the Rambam's definition of "average", meaning having exactly equal (quantitatively+qualitatively) merits and bad deeds, it wouldn't align at all with the reality of his actions.