We apply optimal control theory to a generalized SEIR-type model. The proposed system has three controls, representing social distancing, preventive means, and treatment measures to combat the spread of the COVID-19 pandemic. We analyze such optimal control problem with respect to real data transmission in Italy. Our results show the appropriateness of the model, in particular with respect to the number of quarantined/hospitalized (confirmed and infected) and recovered individuals. Considering the Pontryagin controls, we show how in a perfect world one could have drastically diminish the number of susceptible, exposed, infected, quarantined/hospitalized, and death individuals, by increasing the population of insusceptible/protected.