Each quest / stage consumes a certain amount of energy points.
The cost is usually displayed before you enter the level.
Energy naturally replenishes over time, or it can be refilled instantly through the use of Diamonds.