Optimal planning and resilient operation of microgrids with renewable energy sources