Demand response optimization in grid-connected and islanded microgrids with renewable energy sources and storage systems