A variational formulation with rigid-body constraints for finite elasticity: theory, finite element implementation, and applications