Stabilized sequential quadratic programming for optimization and a stabilized Newton-type method for variational problems