Well, you definitely retain your class levels. If someone casts Dispel Magic on you, you'll become a level 20 Sorcerer.
However, True Polymorph does not allow you to use your class features (including the Spellcasting class feature). Compare it to the Druid's Wild Shape ability, or the Shapechange spell, both of which include this paragraph:
You retain the benefit of any features from your class, race, or other source and can use them if your new form is physically capable of doing so. However, you can't use any of your special senses, such as darkvision, unless your new form also has that sense.
Additionally, neither Wild Shape or Shapechange include the phrase "The creature is limited in the actions it can perform by the nature of its new form" that True Polymorph does. It seems clear that True Polymorph restricts you to doing things your new form is inherently capable of doing, whereas Wild Shape and Shapechange allow you to do anything you're normally capable of as long as your new form is physically able to do it.
More intuitively, True Polymorph has an offensive use written in to it. The classic "turn your opponent into a frog" move doesn't really mean much if they become a powerful spellcasting frog wizard, or a stealthy sneak-attacking frog ninja. In some cases, it might even be a boost.
Not much.
Let's go to the text!
True Polymorph (PHB p. 283):
If you turn a creature into another kind of creature, the new form can be any kind you choose whose challenge rating is equal to or less than the target’s (or its level, if the target doesn’t have a challenge rating).
The word "kind" seems to be pretty important here, so let's see if any other spells or other rules use it in this way:
Antipathy/Sympathy (PHB p. 214):
Then specify a kind of intelligent creature, such as red dragons, goblins, or vampires.
Locate Creature (PHB p. 256):
The spell can ... the nearest creature of a specific kind (such as a human or a unicorn) ..
Special Purpose (sentient magic items) (DMG p. 216):
Protector: The item seeks to defend a particular race or kind of creature, such as elves or druids.
Wand of Orcus (DMG p. 227):
While attuned to the wand, Orcus can summon any kind of undead, not just skeletons and zombies.
Examples we have of "kinds of creatures" are: red dragons, goblins, vampires, humans, unicorns, elves, druids, skeletons, zombies. So, that implies that that is the level of choice a spellcaster has when casting True Polymorph.
To address your examples, it seems like "elf" and "drow" are viable choices, but nothing more specific than that.
As far as physical sex goes, some kinds of creatures (marilith demons, androsphinxes and gynosphinxes, hags) are inherently constrained to specific forms, but in other cases, it's not specific to the kind of creature selected, so it's not something the caster chooses. As a DM I would generally either have the post-polymorph character be of no particular physical sex, or be of the physical sex most nearly equivalent to that of the character before the transformation.
Any other aspects of appearance are up to the DM. They might declare that polymorphed creatures bear some resemblance to their previous forms, or they might declare it to be completely random.
Also, consider this sentence from the related spell shapechange (PHB, p. 275):
You transform into an average example of that creature, one without any class levels or the Spellcasting trait.
So shapechange doesn't allow the caster to specify specifics of appearance, restricting them to an "average example" of the kind of creature they have chosen. It seems reasonable to infer the same kinds of limitation apply to the polymorph spells as well.
Best Answer
Rules Stuff
Well, for starters, polymorph can only turn things into beasts. Which is to say, creatures with the beast type - so no humanoids.
As for true polymorph, well...technically, by the rules, you can only use true polymorph to turn a creature into a creature with a Challenge Rating.
The target doesn't need a Challenge Rating, it can use its level - so it works on PCs. But the new form has to have a Challenge Rating, so you can't turn a PC into a PC, so to speak.
That means that, for example, turning your buddy the Human Fighter 20 into an Elf Fighter 20 isn't going to work. On the other hand, you could turn him into a Drow Elite Warrior (CR 5). So, changing a creature's race with true polymorph is possible, it's just not simple.
By the same token, you can't turn your buddy the Male Human Fighter 20 into a Female Human Fighter 20. However, (and this is why I picked drow), you could turn him into a Drow Priestess (CR 8). It's a little questionable whether this would actually change his gender, though.
Again, going by the rules, true polymorph replaces the game statistics of a creature with those of another creature. But there's no clear evidence that gender is a game statistic. The Monster Manual has a very long section on Statistics, and gender isn't mentioned anywhere.
Any transformation along these lines will allow the use of hands and speech.
Non-Rules Stuff
You may well have read all that and thought "That's stupid!" every step of the way. True polymorph is a 9th-level spell, up there with wish in terms of cosmos-altering power. It can turn a kraken into a crab, or a dragon into a dog.
That being the case, the easiest solution (as always) is to talk to your DM. If you say "Hey, can I use true polymorph to change race and/or gender?" then you'll get the answer that is true for your game.
Of course, if you are the DM, that doesn't help you all that much. If a player asks you this, and you're wondering what to say, well, it's up to you. I will warn you that allowing true polymorph to turn creatures into forms other than the ones with a CR and a statblock opens it up to some weird abuses and crazy shenanigans. So how you rule on this is up to you, but it might be worth having a think about how much you trust your players, and how okay you are with having this stuff in your game.