Online energy management