Optimal control of a heavy duty diesel engine with EGR and VGT during transients is investigated. Minimum time and fuel optimal control problems are defined for transients from low to high output torque. A validated diesel engine model is used with minor changes in order to be suitable for the selected solver. The problem is solved for several feasible minimum EGR fractions and smoke-limiter values in order to provide comparisons. The optimization results show that the smoke-limiter has great effect on the transient duration while the required EGR fraction influences the control signals' shape. The fuel optimal control keeps the control actuators more closed than the time optimal, however both time and fuel optimal results become very similar when high EGR fractions and smoke-limiter values are required.