The main indicators of the severity of an epidemic outbreak are not only the disease prevalence or incidence levels, but also the time needed for the eradication. However, few attempts have been made to address the problem of minimizing the epidemic duration from a theoretical point of view by using optimal control theory. To this aim, we consider a time-optimal control application to a SIR basic model implementing two alternative strategies: vaccination and isolation. The problem is subject to several constraints, including limitations on the maximum rate of control efforts and on the total amount of resources available during the whole outbreak. Applying the Pontryagin minimum principle we prove that only bang-bang controls with at most two switching times are admissible. Numerical simulations support the analytic findings and highlight the role of the accounted restrictions. Finally, a more general control problem is presented in order to minimize both epidemic duration and size.