Off-Line and On-Line Optimization Under Uncertainty: A Case Study on Energy Management