A Dynamic Relaxation Technique for Determining the Structure and Stability of Coronal Magnetic Fields