First, always start with monster stat blocks when creating NPC opponents for the players.  PCs are balanced around session after session of damage, with healing in between.  Monsters are balanced around one fight, after which they are likely dead.

Second, (in my experience as a DM making many homebrew monsters) starting with a monster of approximately your desired CR, and then swapping things out and re-flavoring them is much easier than taking a more similar monster and leveling them up.  Because it is sometimes hard to understand how adding a new feature will affect the CR of the monster.

For your situation, I would suggest starting with the Lich.  It's CR21, and a spellcaster.  You may need to change out stuff, but finding something that has a similar effect will help prevent changing the CR too much.

---

As a final note: action economy is a cruel mistress.  When your 3-5 PCs all gang up on 1 creature, it doesn't take much to bring it down.  If each PC deals say, 30 DPR (about average for non-spell DPR with 75% chance to hit), then your PCs are dealing 90-150 DPR vs one monster.  So if you want it to last 3+ rounds, it needs 300+ HP. More if you have spellcasters.

But, if your BBEG has 3-5 minions, then the PCs either have to take their hits to focus damage on the BBEG, or spend a round or two taking out the hired help before going after the BBEG.  That will make your fight last longer without having to have a spellcaster with 300+ HP.