The problem of operating freeze drying of pharmaceutical products in vials loaded on trays of freeze dryer to obtain a desired final bound water content in minimum time is formulated as an optimal control problem. Two different types of freeze dryer designs were considered. In the type I freeze dryer design, upper and lower plate temperatures were controlled together, while in the type II freeze dryer design, upper and lower plate temperatures were controlled independently. The heat input to the material being dried and the drying chamber pressure were considered as control variables. Only the scorch temperature was considered as a constraint on the system state variables during the secondary drying stage, because all the free water content (frozen water) is removed from the solid matrix during the primary drying stage of freeze drying. Necessary conditions of optimality for the secondary drying stage of freeze drying process in vials were derived and presented by using rigorous multidimensional unsteady-state mathematical models. The theoretical approach presented in this work was applied in the freeze drying of skim milk. Significant reductions in drying times of the secondary drying stage of the freeze drying process in vials were observed and more uniform bound water and temperature distributions in the material being dried were obtained compared to the conventional operational policies.