In this paper, we develop a framework for determining optimal respiratory airflow patterns for a multicompartment lung mechanics system with nonlinear resistance and compliance parameters. First, a nonlinear multicompartment lung mechanics model that accounts for nonlinearities in both the airway resistances and the lung compliances is developed. In particular, we assume that the resistive losses are characterized by a Rohrer-type model with resistive losses defined as the sum of linear and quadratic terms of the airflow. The proposed model is more realistic than those presented in the literature, since it takes into account the heterogeneity of lung anatomy and function as well as the nonlinearity of lung resistance and compliance parameters. This model can be used to provide a better understanding of pulmonary function as well as the process of mechanical ventilation. Next, using the proposed nonlinear multicompartment lung model, we develop a framework for determining optimal respiratory airflow patterns. Specifically, an optimization criterion that involves the minimization of the oxygen consumption of the lung muscles and lung volume acceleration for the inspiratory phase, and the minimization of the elastic potential energy and rapid airflow rate changes for the expiratory phase is formulated and solved. The solution to the formulated optimization problem is derived using classical calculus of variation techniques. Finally, several illustrative numerical examples are presented to illustrate the efficacy of the proposed nonlinear multicompartment lung model and the corresponding optimal airflow patterns. Comparison with experimental data shows that our nonlinear resistance model predicts the airflow patterns more accurately than linear resistance models. Moreover, the optimization criterion used in this paper also provides a more accurate prediction of the optimal airflow patterns.