Management of invasive species involves choosing between different management strategy options, but often the best strategy for a particular scenario is not obvious. We illustrate the use of optimization methods to determine the most efficient management strategy using one of the most devastating invasive forest pests in North America, the gypsy moth (Lymantria dispar), as a case study. The optimization approach involves the application of stochastic dynamic programming (SDP) to a metapopulation framework with different infestation patch sizes, with the goal of minimizing infestation spread. We use a novel "moving window" approach as a way to address a spatially explicit problem without being explicitly spatial. We examine results for two cases in order to develop general rules of thumb for management. We explore a model with limited parameter information and then assess how strategies change with specific parameterization for the gypsy moth. The model results in a complex but stable, state-dependent management strategy for a multiyear management program that is robust even under situations of uncertainty. The general rule of thumb for the basic model consists of three strategies: eradicating medium-density infestations, reducing large-density infestations, and reducing the colonization rate from the main infestation, depending on the state of the system. With specific gypsy moth parameterization, reducing colonization decreases in importance relative to the other two strategies. The application of this model to gypsy moth management emphasizes the importance of managing based on the state of the system, and if applied to a specific geographic area, has the potential to substantially improve the efficiency and cost-effectiveness of current gypsy moth eradication programs, helping to slow the spread of this pest. Additionally, the approach used for this particular invasive species can be extended to the optimization of management programs for the spread of other invasive and problem species exhibiting metapopulation dynamics.