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 croaking non-allied Units in battle. 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 two 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. Anyway, the approximate Experience and how near a unit is to level does seem to be knowableLIAB 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. However, the fact that Parson is still only Level 2 even after the grand TPK at Gobwin Knob (and no one is surprised about this) undermines this theory. Maybe only kills made by the stack under direct command of the Warlord would give experience. Or, maybe Stanley was just more worried about leveling his Warlords (of which he had very few) than his Dwagons (of which he had plenty and which are tough to begin with).
Units may gain small amounts of experience by training, although at much slower rate than in real battle.