This paper is devoted to a model of epidemic progression, taking into account vaccination and immunity waning. The model consists of a system of delay differential equations with time delays determined by the disease duration and immunity loss. Periodic epidemic outbreaks emerge as a result of the instability of a positive stationary solution if the basic reproduction number exceeds some critical value. Vaccination can change epidemic dynamics, resulting in more complex aperiodic oscillations confirmed by some data on Influenza A in Norway. Furthermore, the measures of social distancing during the COVID-19 pandemic weakened seasonal influenza in 2021, but increased it during the next year. Optimal control allows for the minimization of epidemic cost by vaccination. © 2023 by the authors.