The capacity of lithium ion batteries can be improved through the use of functionally graded electrodes. Here, we present a computational framework for optimizing the layout of electrodes using a multiscale lithium ion battery cell model. The model accounts for nonlinear transient transport processes and mechanical deformations at multiple scales. A key component of the optimization methodology is the formulation of the adjoint sensitivity equations of the multiscale battery model. The efficient solution of the adjoint equations relies on the decomposition of the multiscale problem into multiple, computationally small problems associated with the individual realizations of the microscale model. This decomposition method is shown to significantly reduce the computational time needed for sensitivity analysis versus numerical finite differencing. The potential of the proposed optimization framework is illustrated with numerical problems involving both macroscale and microscale performance criteria and design variables. The usable capacity of a lithium ion battery cell is maximized while limiting the stress level in the electrode particles through manipulation of the local porosities and particle radii. The optimization results suggest that optimal functionally graded electrodes improve the performance of a battery cell over using uniform porosity and particle radius distributions. Copyright © 2012 John Wiley & Sons, Ltd.