Many problems in biology are governed by a dynamical system of differential equations with unknown parameters. To have a meaningful representation of the system, these parameters need to be evaluated from observations. Experimentalists face the dilemma between accuracy of the parameters and costs of an experiment. The choice of the design of an experiment is important if we are to recover precise model parameters. It is important to know when and what kind of observations should be taken. Taking the wrong measurement can lead to inaccurate estimation of parameters, thus resulting in inaccurate representations of the dynamical system. Each experiment has its own specific challenges. However, optimization methods form the basic computational tool to address eminent questions of optimal experimental design. In this paper we present a methodology for the design of such experiments that can optimally recover parameters in a dynamical system, biological systems in particular. We show that the problem can be cast as a stochastic bilevel optimization problem. We then develop an effective algorithm that allows for the solution of the design problem. The advantages of our approach are demonstrated on a few basic biological models as well as a design problem for the energy metabolism to estimate insulin resistance.