Variational theory of deformations of curved, twisted, and extensible elastic rods