OPTIMAL RULE BASED ENERGY MANAGEMENT AND SIZING OF A GRID CONNECTED