Microgrid Energy Management with Flexibility Constraints: A Data-Driven Solution Method