A variational principle for weighted Delaunay triangulations and hyperideal polyhedra