Distributed Optimization For Energy Management In Microgrids