You need to have written out much of the battle beforehand. There will be only a few areas/critical points where a handful of 5th level guys can make much of a difference - and the overall battle will probably unfold much the same, regardless of your group's actions. Don't bother rolling for enemy units vs. home units etc. Just tell the players what happens 'in the backdrop', while their PCs get assigned critical mission after critical mission.
Depending on the success of those 'special forces' actions (what else are adventurers, militarily speaking?), the players might begin to see the general trend shift this way or that. And what was a close battle to begin with slowly turns into the favor of one side or the other, depending on the PCs's successes or failures - to a degree.
Keeping the balance is tricky here. You must make the players feel they can have a meaningful impact and might just sway their side's fortune enough - but they must not make the mistake of thinking their actions control the whole battle like a marionette.
Example missions and their possible impacts include:
1. Holding a key point (a defensive tower, a gate, a 'back door', a hidden entrance) for long enough for reinforcements to arrive, or against a powerful foe that 1st level warriors can't fight effectively.
-- Succeeding saves a lot of lives and takes out a chunk of elite attackers. Make sure to mention at a later date how masses of low-level grunts were sent to their deaths in another unsuccessful bid to wrest the gate/tower from the defenders, and how the enemy lost a lot more troops than planned due to this.
-- Failing the objective means a precious reserve unit has to pick up the slack, losing many fighters, and being unable to redeploy later. These people will be sorely missed in some of the fights to come.
2. Assassinating an enemy officer, or even part of its staff, in a quiet part of the front where fighting hasn't yet begun.
-- Succeeding sees the enemy redeploy in that sector, sending troops into battle haphazardly or without effective leadership. That part of the front is the last to fall, or can become a place where the defenders can rally time and again.
-- Failing the mission means there's no weak point in the enemy's assault, nowhere to take a breather, and reserves have to be committed everywhere equally instead of only at some fewer points. The whole affair is more likely to turn into an attriting grind, favoring the more numerous attackers.
3. Taking out or at least damaging a choice piece of siege equipment (think Grond) before it can be deployed.
-- Succeeding makes sure there's no one point where the attackers can assault with overwhelming force. Instead, they're reduced to conventional, high-casualty tactics. Over a few hours, this can make a big difference, even if Grond is repaired and put into the battle later.
-- Failing means there's one area of the walls (main gate, or just one breached wall) where the enemy can get in more or less unmolested. It will take many of the few resources at the defenders' command to plug this gap, if it is even possible at all. A whole city level might be lost to this alone!
4. Saving and protecting an important hero or officer of the defending side.
-- Success results in a huge morale boost, meaning people will fight longer and flee less. Make sure to have the saved NPC lead a crucial rearguard action/relief assault later on, put together from formerly fleeing/lightly wounded soldiers.
-- Failure dents morale even further. The lost hero's father/brother/friends might even lose it completely and go for a suicidal attack to join their loved one in death!
5. Behind-the-walls support activity, like putting out fires quickly using magic or mundane means (Red Hand of Doom has a nice example of this), or rallying a shattered, fleeing unit, or quickly relaying news of import ("west gate under heavy assault, need relief ASAP!"), or even stopping suicidal orders from a high command gone mad before they reach the soldiery!
-- Success/failure: varies a lot, I think I've typed enough now to give you some ideas.
Bottom line: let the battle unfold naturally, with some possible turning points in the back of your head. Success/failure of PC actions doesn't need to have immediate consequences. But if the PCs thwarted easy entrance into the city time and time again, stress how the enemy slowly bleeds itself to death against seemingly impervious walls, until their will seems to break. If the PCs managed to extricate the Lord High Mage from danger, let him turn the tide in a later skirmish somewhere the PCs can see. If the PCs stole the enemy staff's maps of the "Second Level Maze" defensive structure, give them a chance to ambush and defeat-in-detail some haphazard, disorganized enemy companies there later on. You get the gist.