I am playing Heroes of Might & Magic IV and I have the problem that sometimes I engage an enemy army and get whacked. How can I know ahead of time whether an army is too strong for me, or what casualties I might suffer?
There is no golden rule, as too many factors can affect battle result.
But I can give a few hints on how one can understand battle difficulty:
You should know number of creatures you are going to face. Without scouting skill / mods you can see only estimate size, which translates as (source):
All creatures have level - from 1 to 4. It's rough estimate of creature power, let's say that creature of level 2 will always beat any level 1 creature without hero's bonuses in 1 on 1 fight. You should learn creature levels or use some cheatsheets for it - for example, Nature Creatures. It's not a good idea to attack Dozens of 4 level creatures without at least Band of your own level 4s.
Learn creatures special abilities. There are lots of them and they are hard to remember, but you can always check them during battle. For example, Efreet has Fire Shield, which reflects some % of melee damage back to attacker, it's better to shoot Efreets from distance!
Difficulty affects enemy tactics. For example, on next-after-normal difficulty enemy creatures begin to wait instead of rushing onto your army. Also with higher difficulty neutral creature packs become stronger, and sometimes strong packs prevent AI players from expanding.
Fights against armies with heroes are always more dangerous as heroes provide bonuses to creature stats. Heroes itself can cause a lot of problems with smart use of artifacts / spells / potions.
Armies inside towns have advantage because of walls and towers. So plan your sieges carefully.