Hi!

If they outnumber you - break their morale. Try to kill the enemy general. It would be a good idea to have some archers and slingers. Archers uses fire and they break morale, slingers are fast moving and very effective against the armour.
So slingers and archers attack phalanx. Phalanx follow slingers, as they are slow and cant reach slingers they tired and losing morale.
The amount of enemy melt, they have no general, they scare of archers' fire.
When you have no arrows it is time to attack. ( If you have shock infantry like nacked celtic warriors it's great! ) Attack one of them with all your forces and the enemy will run. Others will see it and run too.
???
Profit!!!