A mathematical framework is presented that allows the efficient calculation of stability properties and control strategies for fluid flows. The framework is based on an optimization scheme using a variational formulation. Adjoint equations and optimality conditions are used to compute the necessary gradient information and to advance the cost objective to an extremum. The proposed scheme is then applied to swept attachment-line boundary layers, and disturbances favored by the non-homogeneous mean flow are determined together with their temporal evolution. The same optimization scheme is then used to apply an optimal blowing/suction strategy to minimize the rise of previously identified instabilities.