Optimal bidirectional charging control of Electric Vehicles