The use of actuators with inherent compliance, such as series elastic actuators (SEAs), has become traditional for robotic systems working in close contact with humans. SEAs can reduce the energy consumption for a given task compared to rigid actuators, but this reduction is highly dependent on the design of the SEA's elastic element. This design is often based on natural dynamics or a parameterized optimization, but both approaches have limitations. The natural dynamics approach cannot consider actuator constraints or arbitrary reference trajectories, and a parameterized elastic element can only be optimized within the given parameter space. In this work, we propose a solution to these limitations by formulating the design of the SEA's elastic element as a non-parametric convex optimization problem, which yields a globally optimal conservative elastic element while respecting actuator constraints. Convexity is proven for the case of an arbitrary periodic reference trajectory with a SEA capable of energy regeneration. We discuss the optimization results for the tasks defined by the human ankle motion during level-ground walking and the natural motion of a single mass-spring system with a nonlinear spring. For all these tasks, the designed SEA reduces energy consumption and satisfies the actuator's constraints.