Experience is a theoretical statistic, conceived of by natives of Erfworld to explain why and when leveling occurs. Experience is a hidden statistic of Units, hidden even from the unit itself. Experience is gained through practising at the unit's skills, such as by training, croaking non-allied Units in battle, or by casting spells. Once enough Experience has been gained, the Unit gains a Level (or in some instances, more than oneErf-b1-p132). The Leveling event can be a surprise to the unit.
Units in Erfworld have difficulty determining how much croaking it takes to gain a level for three reasons. First, the statistic is not available to be seen, and the amount of experience gained from croaking an enemy unit is not known. Second, it is difficult to arrange for a set number of particular enemy units to be available to kill in order to run an objective test. Third, the amount of experience gained is at least partially dependant upon how much the unit was actually able to learn, which is more or less intangible to anyone who isn't a Date-a-mancer. Nevertheless, the approximate Experience and how near a unit is to level does seem to be estimableLIAB 10:8.
Warlords may gain experience from winning battles, as well as from croaking Units. On Turn 3, after Parson reveals that he already commited Gobwin Knob's forces to battle without Stanley's knowledge, Stanley becomes angry that his Warlords won't Level up due to the withdrawal from all fights, but not worried that his precious dwagons won't. This suggests that Units still gain experience for croaking enemies, regardless of the outcome of the battle (or alternatively, that Stanley was simply more worried about leveling his precious few Warlords). This theory is indirectly supported (or rather, not contradicted by) the fact that Parson did not level after the grand TPK at Gobwin Knob, which for all purposes was a great victory but which involved Parson retreating into the Magic Kingdom before the battle was over (presumably losing out on all the XP).
Units may gain small amounts of experience by training, although at much slower rate than in real battle.