I'll suppose you have 2 fighters, 1 mage and 1 cleric:
Fighters: You should have a Holy Destruction +4 weapon for each. For armor I prefer Adamantium Fullplate of Fortification 3. For rings, ones that give resistances(Greater Fire and Acid for instance). +6 str belt, +6 con amulet, +6 dex bracers, +6 wisdom helm. Boots of striding. Cloak of displacement or +5 to all saves.
Pretty much the same items for wizard and cleric(except worse armor and int6 headband for wizard).
For wizard spells:
9th Dominate Monster(it's the most powerful spell in the game objectively, although less useful in this battle compared to the true final bonus battle). Energy drain is useful against the dragon IF you can penetrate spell resistance(big if, since it has a huge one)
8th Irresistable Dance(for the dragon) and dehydrate(for the mooks)
7th Waves of exhaustion and discharge
6th Greater Heroism(makes hitting the dragon MUCH easier if cast on fighters)
5th Wall of stone
4th Fire shield and stoneskin(possibly cast on fighters).
3rd Haste(extremely useful)
2nd Web(better than the spell level implies)
1st Magic missile(useful in many situations)
Cast Wall of Stone to prevent enemies from getting line of sight on you(and thus using spells and bows and such). Cast haste, heroism and such behind the wall and prepare for the battle. Once the wall is down, dehydrate enemies and finish them off with fighters. Once the dragon is left, use Web(if fighters have cloak of spider) or Irresistable dance. Possibly waves of exhaustion or dischage. If you're feeling lucky, cast fire shield(cold version) on a fighter and grapple the dragon. It makes it easier for the other fighter to hit the dragon(although the dragon will likely kill the fighter grappled quickly).
9th Mass Heal, Mass Harm, True resurrection
6h Heal, Harm
5th Greater protection from evil, Righteous might(if your cleric is good in melee)
4th Freedom of movement(if the dragon grapples and you don't like it), Divine power(if melee cleric)
3rd Mass protection from evil
After wizard has cast wall of stone, cast mass protection from evil on the party, or multiple greater protection from evils. After wall is down, use firestorm to deal damage, or mass harm. After your useful spells have been cast, use righteous might and then divine power and attack the dragon with the fighters(unless you feel its more useful to heal the fighters when they take damage)
Hope it helps, I don't recall the battle completely but I think something like this should make it easier. Of course, if you've used a similar tactic, then I guess luck is a big factor.