Optimal control strategy to reduce the temporal wavefront error in AO systems