An army marches on its stomach. The world-devouring necromancer's primary enemy is logistics: how to get enough humanoids to power your bodyworks in a short enough time to prevent massive unified retaliation by the world's more annoyable wizards and clerics.
While consuming the souls of bunnies (as suggested by a previous edit) is both cute and delightful, bunnies lack two critical prerequisites: the humanoid type and an intelligence score.
The central plan here is the idea of the "Wraith Pit" (freely stolen from a previous game I was in.) Wraiths have the ability:
Wraiths have the ability:
Create Spawn (Su)
Any humanoid slain by a wraith becomes a wraith in 1d4 rounds. Its body remains intact and inanimate, but its spirit is torn free from its corpse and transformed. Spawn are under the command of the wraith that created them and remain enslaved until its death. They do not possess any of the abilities they had in life.
Now, the optimal undead horde will have three requisites: the ability to ignore the controlled HD limit but still retain control, the ability to create spawn, and incorporeality.
The biggest problem with the optimal undead horde is growing them properly. The second biggest problem is a sudden loss of control. The third biggest problem is "getting there firstest with the mostest."
The first route is the Full Metal Alchemist. Build a utopian city (preferably an arcology with exactly 5 foot thick floors). Provide free services and a wonderful way of life. Criminals, are, of course, put in "eternal sleep." When the city reaches a useful size, let loose your primary wraiths and consume it. The downside is that "utopia with slight evil at its core" doesn't provide "hordes of undead" until the final step.
The second route is the spectre/wraith/shadow horde. The spectres are nice because a hit from them bestows two negative levels, which suggests a round or two to kill a commoner. In a deep sewer, desecrated, with a shrine to... $evilGuy, haul the homeless, travelling merchants, and other people no one will miss. In that place, your incorporeal undead should nom on the living. Specifically, your "leader" of the city should turn people into wraiths/shadows/spectres. By having a very flat hierarchy, you introduce a flaw into your system (single point of failure) but make it very hard for groups of your minions to be uncontrolled. If you're going this route, you'll want to target every city of a kingdom simultaneously. To do this, you'll need to have the Necrotic Cyst and the ability to cast Necrotic Tumor. That way, you can turn high-ranking people inside the prisons, government, and clerical orders before starting this plan. Then it's a simple matter of funneling the city's undesirables to the desecrated zone until you have, roughly, a spectre per household. Then pull the trigger as the sun goes down. After a few minutes, you'll have converted most of the kingdom. So long as you've necrotic tumored enough clerics and wizards, anyone who's managed to resist can get slaughtered by their "friends." If doing this on a long term plan, don't forget to build hospitals, orphanages, and tenements.
For this sort of style of play, the direct confrontation with the BBEG will likely be somewhat anticlimactic. While rebuking an honour guard of undead is cool, your earliest bet will be via metamorphic transfer.
For this sort of behind-the-scenes "do gooder" builder of hospitals, orphanages, prisons, and spectre factories, I'd probably recommend a spell-to-power erudite 6/ur-priest 2/psychic theurge 6 (the levels after this get tricky, but that's not the point.) Erudite is horrible at adventuring, but great at casting a number of really tricky spells per day. During preparation, you'll be travelling around, planting necrotic cysts in everyone at level 3. The erudite is mainly to get you access to any arcane spells. The bard spell list in particular is nice for social scmoozing and sneaking about. It's also necessary to get manifester level 5th for metamorphic transfer. You may want to dip your first level into binder (for naberius, always useful when working around undead and in social situations), tenebrous apostate, and the divine version of anima mage. In any event, you'll want to be a necropolitan, and use alter self at level 5 to, combined with metamorphic transfer, turn into a shadow (and) Wraith, and start those armies breeding slowly. Search this list for things under 5HD that can create spawn, ensure that they create spawn that are under their control, and go to town. Metamorphosis at 13th level will open up other spawning options, as ur-priest gives you the various divine animation spells that are also handy.
Level 13 also gives you necrotic tumor, so you can ripen all of the cysts you've (and your followers) have been planting for years. All it really takes is time, and access to the minds of spellcasters.
Level 14 allows you to metamorph into a Mohrg, which will allow you to animate as many zombie rabbits as you desire. Since there's no cap, It's an excellent way to build a huge army of rotting fur and cuteness. There are benefits here, too. Zombie rabbits (and other cute animals) will cause people to leave the countryside and increase the population of cities. Therefore, you can use your "zombie threat" to both scare off villages, lull your enemies into a false sense of security (who wants to be hired to vanquish zombie rabbits?), and concentrate your primary food where you want it. With that said, there's nothing stopping you from doing the same to dragons, but the world takes zombie dragons far more seriously.
You'll also want a cadre of significantly less stealthy crypt chanters. Getting the first one will be very tricky. With a stretch (a very big one) you can grab the mantled erudite ACF, take the natural world mantle, and use the suggested "substitute powers" pseudo-acf in minds-eye to swap earthquake for greater shapechange. Unfortunately, that will have to wait until level 19 for it to be of any utility. It might be worth dipping into a PrC which provides the animal domain, which allows you to get shapechange when the ur-priest reaches 9th level spells. (level 15-16, depending). Crypt chanters have an excellent chance of enthralling huge groups of organised opposition, and eventually converting them into more crypt chanters. You'd want to have a chorus of at least 4 of them before trying to convert any sizable forces, but if you have a brass band of them singing row-row-row your boat (with a portion stopping every round to reset the saving throws), they are exceptionally hard to beat. If you issue your forces with wands of dispel magic to dispel death wards, you can use quantity to wear down even the scariest of Pelor's clerics. (Beware the ablative zombie bunny hordes!)
CR 23
Specifically, you can permanently enslave Acererak, the demilich, in his Tomb of Horrors. No undead has a higher CR so you can't really do better than that1.
To enslave Acererak, one ought first to Feeblemind him and apply several high-level copies of Bestow Curse2. This is not easy, as Acererak has a +11 bonus on Int saves, a +9 bonus on Wis saves, and 3 free saves per day from legendary resistance. Still, it is possible, and not even terribly difficult for a 20th level wizard with access to Bestow Curse, Glyph of Warding, Feeblemind, and Gate (though it will be quite expensive).3
Once Acererak is reduced to 1 intelligence and charisma, given disadvantage on Charisma and Wisdom saves, and made to make a Wisdom save on each turn or lose its action, you should have allied casters with access to bane (e.g. a drider or Koa-Toa whip created via true polymorph and controlled via dominate person via glyph of warding to bypass concentration) cast bane on the demilich till it sticks. This gives Acererak a charisma save of 1d20+1-1d4 with disadvantage. As a 20th level wizard with 30 intelligence4, your save dc should be 24. With a Robe of the Archmagi, your DC goes to 26. This means that even with a 20 Acererack is unable to resist your Command Undead class feature, and becomes your slave.
Since a feebleminded demilich is much less useful than a functional one, we next need to deal with that. Greater Restoration (accessed via true polymorph on an object into a Coautl, combined with dominate monster via glyph of warding if necessary) eliminates the Feeblemind without hurting the rest of the debilitating effects.5
Immediately after restoring the demilich's mind, order it to use its teleporting randomly within a 300 mile radius and lowering a stat by two permanently ability on itself choosing intelligence until its intelligence score is 10 or 11. This must be achieved within 1 hour. Once the lich's int score dips below 12, he stops being entitled to hourly saves and instead serves you without any further saves forever (or, at least, until control is actively lost). If a save is incurred during or as a result of this transition period, it is 1d20 +11-1d4 without advantage versus DC 26. That's about a 17.5% (a little less than 1 in 5) chance of us failing, which we can mitigate by forcing a reroll with a Luck Blade for a total of 3.06% (a little less than 1 in 30) chance of losing the demilich permanently per roll. 6
Note that, in practical terms, regular liches make better servants that Acererak does since they can move and cast spells and Acererak can't really. Acererak has a higher in-lair CR, though.
Okay, actually ancient red or gold dracoliches are CR 24. But 1) Acererak is way famouser, and 2) the same technique (except lowering via other methods, unless you have an Acererak sitting around) would work on a dracolich in the same way, it's just easier because Acererak has a +11 intelligence save instead of a measly +4. In fact, dracoliches can be easily taken down with just a horde of intellect devourers, which is sad. Reminiscent of earlier editions, but still sad.
To capture a dracolich variant spellcaster, have a horde of intellect devourers you control set its intelligence to 0 and leave it permastunned as soon as you release the lich from Feeblemind, which you do after Polymorphing it into a swarm of rats or similar. Since the rats are immune to stunning, the Dracolich will have 0 int without the penalty of being stunned. Undoing the polymorph doesn't remove the effect setting Int to zero, but it also doesn't cause the lich to be stunned. Dracoliches, like all dragons, use Charisma as their spellcasting attribute, so 0 int isn't a big deal. Alternatively, you can use a scroll of Power Word Heal, if you happen across one.
Bestow Curse may stack weird in some games, see this Q+A If it does, you'll need to cycle through curse effects to make this work. You can probably do that just by redefining what curse effect is 'more powerful' repeatedly, but worst comes to worst you can spend the months of time and tons of gold to make the necessary Remove Curse and Bestow Curse cycles operate via Glyph of Warding.
You do this by casting Glyph of Warding a bunch of times with Feeblemind in it, obviously. You also have some Glyphs with Bestow Curse and maybe some other debuff-y spells too if you want. You can't put Bane in here, cause you don't know it cause it's not a wizard spell. You then take a long rest, and cast Gate on the last round of said long rest so that you immediately regain all your spell slots and can cast a 9th level spell again right away. This works because it takes an hour of interruption to stop a long rest from completing. Since you need to be sure the lich fails the save four times, you need a lot of Feebleminds. Specifically, you need 15 Glyph of Wardings with Feebleminds to have a 99.99% chance of success. That costs 3000 gp to create and takes 15 days to create for a 20th level wizard. You also want the curses to stick which means, to be safe, spending another 11400 gp but no additional days to the contruction time.
If you have a Tome of Clear Thought, you and anyone you want have 30 Intelligence, assuming you're willing to pass time for the book to recharge, for example by putting the book on a plane where time moves faster or by going to a plane where time moves slower or both, or by entering temporal stasis, or by finding a way to magically age the book or whatnot. Regardless, if you have 5 Tome of Clear Thoughts, you have 30 int.
If you, for some reason, didn't or couldn't track down a Tome of Clear Thought by level 20 as a wizard, your intellect will probably be limited to a mere 20, which puts your save DC as a mere 19 or 21 with a Robe of the Archmagi. Don't do this to yourself.
We can't use glyphs for True Polymorph, because the spell is 9th level and we only have 1 9th level spell slot, unless we also have a Tome of the Still Tongue. That's why we may need to, instead, create creatures on prior days and cage them, then use Glyphs to Dominate them on the last day. We probably shouldn't need to do this, because we probably have 30 Charisma and no reason to treat our servants badly and they have no reason not to obey us, but maybe we do or we're super evil or something. Setting this up adds weeks of time and tens of thousands or gold pieces in expenses if you decide to do it the Dominate-y way.
We need the Coautls (or similar) because Greater Restoration is not on the Wizard list, and that spell or Heal are needed to remove the Feeblemind without removing other things we want to keep.
Admittedly, the only benefit Acererak derives as a servant from not being Feebleminded is that he can communicate intelligibly and has a +5ish bonus on Int and Cha saves. Nonetheless, in the case of a proper lich Intelligence is a very important stat so understanding how to undo the Feeblemind without losing control is important in general.
The intelligence is lost when the curse is removed, which you can do by casting Remove Curse. You'll need to track down or gate to you or otherwise undo the random teleport's separation 5 times within an hour to avoid letting the lich get a save.
Best Answer
Necromancer Coffeelock
Let's start with the obvious one.
Day 1, Midnight Divine Soul casts Animate Dead (1 minute) - giving 5 skeletons, then uses Font of Magic to convert all the Warlock slots to Sorcerer (18 seconds), and casts Animate Dead 3 more times (3 minutes). Then they take a short rest (1 hour).
01:04:18 Wake up, use convert all Warlock slots to Sorcerer (18 seconds), cast Animate Dead 3 more times (3 minutes), then take a short rest (1 hour).
02:07:36 Repeat this 43 more times
Day 2, 23:29:30 no time to rest again, you can relax for the last 30.5 minutes.
Total skeletons: 5 (from the initial sorcerer slot) + 5 * 3 * 45 (from the warlock slots) = 680 skeletons
Although note that half of them are not under the control of the character, they are walking around doing their own undead things - probably harassing towns and cities. Be aware that since you have to recast the spell every 24 hours to maintain control, you won't see any benefit to the number of controllable skeletons unless you use your first 24 hours to write scrolls or create rings of spell storage.
If you don't have access to those kinds of items, it may be best to start the attack a day earlier sending skeletons to smaller villages or roads to harass people, then spend the second day building up a main force to attack the city.
EDIT: Actually, I don't think it's necessary to convert the slots to sorcerer, so that should save a lot of seconds.
To be clear - by RAW you can rest whenever you want, the DM doesn't get to choose when the character sits down and relax, and converting non-sorcerer spell slots with flexible casting is RAW.. As always, your DM has the final say on what rules you play at your table. Some DMs have expressed that they wouldn't allow it, but I can't speak for your DM.