Many chemical engineering problems require the optimization of systems of differential and algebraic equations. Here a method is presented based on finite-element collocation, which converts differential equations to algebraic residual equations with unknown coefficients. A nonlinear program is then formulated, with residuals incorporated as equality constraints and coefficients as decision variables. Also, adaptive knot placement is used to minimize the approximation error, with necessary and sufficient conditions for optimal knot placement incorporated as additional equality constraints in the nonlinear program. All equality constraints are then solved simultaneously with the optimization problem, thus requiring only a single solution of the approximated model. Finally, problems with discontinuous control profiles can be treated by introducing an extra level of elements (superelements) as decisions in the optimization problem. This approach is demonstrated on a simple optimal control problem as well as a reactor optimization problem with steep temperature profiles and state variable constraints.