The coronavirus disease 2019 (COVID-19) pandemic disrupted public health and economies worldwide. In this paper, we investigate an optimal control problem to simultaneously minimize the epidemic size and control costs associated with intervention strategies based on official data. Considering people with undetected infections, we establish a control system of COVID-19 with time-varying parameters. To estimate these parameters, a parameter identification scheme is adopted and a mixed algorithm is constructed. Moreover, we present an optimal control problem with two objectives that involve the newly increased number of infected individuals and the control costs. A numerical scheme is conducted, simulating the epidemic data pertaining to Shanghai during the period of 2022, caused by the Omicron variant. Coefficient combinations of the objectives are obtained, and the optimal control measures for different infection peaks are indicated. The numerical results suggest that the identification variables obtained by using the constructed mixed algorithm to solve the parameter identification problem are feasible. Optimal control measures for different epidemic peaks can serve as references for decision-makers.