The secret to war is getting the battle odds in your favor. Understand that even with the odds 90% in your favor, you will still occasionally lose... and if you're like me, it'll still piss you off every time.
But anyway, getting the battle odds in your favor is easier said than done... especially because if you're attacking a stack of varried units, the unit with the best chance to win will be defending... so the balanced stack advantage right away goes to the defender. This means that when I'm attacking, I'd expect to lose more units "softening up the defense" and therefore I'd bring more units.
There's a couple techniques to keep in mind while attacking a balanced unit stack. The first has to do with break-points. The best way to illustrate this is with an example:
The enemy brings a stack of 8 macemen and 2 pikemen and 4 trebs. You're safe inside your city for now, but those trebs bombarding your walls and eventually attacking outright, causing collateral damage, are going to be the end of your city if all you do is defend - so you decide that you better attack the attacking stack. Your defending macemen could easily take the trebs and the pikemen, but will have to fight their way through 8 macemen first, which is probably not a good idea. On the other hand, your knights have a much better odds against the macemen and the trebs... but they'll have to get through 2 pikemen first. The weak point in this stack is the pikemen... there's only two. You may have to sacrifice some Knights to take them down, but once they're gone, your remaining Knights are going to have a field day with this stack. Exposing a weakness in a balanced stack is called a break-point. Focus your attacks on exploiting one particular break-point, and once a weakness is exposed, the stack is all but history. However, this will require you to have the units available to do so... which brings me to my second point...
Seige weapons are your best friend. Bring them to every war. Defend your cities with them. Dedicate one of your production cities to building nothing but seige weapons if you can. They will break down enemy stacks and make exposing break-points even easier... imagine the previous example, but instead you started attacking with 4 seige units. Your Knights would then have a much easier time rolling over those injured pikemen, not to mention the macemen and trebs which take collateral damage from Knights (in BTS).
Edit: And, of course... you'll want to bombard city defenses with seige units before attacking a city outright. I forgot to mention this fairly important step the first time.
Pay special attention to the land adjacent to cities... if you're on defence, the AI will attempt to take the best defensive land next to your cities. If you take it first, they will either have to attack you for it or place their military in a sub-optimal position adjacent to your city. Either way, you've gained a battle advantage. If you're attacking an enemy city, find that prime defensive land and you'll give the AI nightmares trying to deal with your attacking stack.
This may not need to be said, but just as you're looking for break-points in the enemy's military stacks, the AI is looking for break-points in yours... it will take advantage of an unbalaced stack... so place enough different types of units in your stacks to where there will be no obvious weakness. A stack is only as strong as its weakest link.