This paper generalizes a previously-conceived, continuation-based optimization technique for scalar objective functions on constraint manifolds to cases of periodic and quasiperiodic solutions of delay-differential equations. A Lagrange formalism is used to construct adjoint conditions that are linear and homogenous in the unknown Lagrange multipliers. As a consequence, it is shown how critical points on the constraint manifold can be found through several stages of continuation along a sequence of connected one-dimensional manifolds of solutions to increasing subsets of the necessary optimality conditions. Due to the presence of delayed and advanced arguments in the original and adjoint differential equations, care must be taken to determine the degree of smoothness of the Lagrange multipliers with respect to time. Such considerations naturally lead to a formulation in terms of multi-segment boundary-value problems (BVPs), including the possibility that the number of segments may change, or that their order may permute, during continuation. The methodology is illustrated using the software package COCO on periodic orbits of both linear and nonlinear delaydifferential equations, keeping in mind that closed-form solutions are not typically available even in the linear case. Finally, we demonstrate optimization on a family of quasiperiodic invariant tori in an example unfolding of a Hopf bifurcation with delay and parametric forcing. The quasiperiodic case is a further original contribution to the literature on optimization constrained by partial differential BVPs.