The work done in straining the shaft with in the elastic limit is called strain energy. consider a shaft of diameter D, and Length L, subjected to a gradually applied torque T. Let θ be the angle of twist. Energy is stored in the shaft due to this angular distortion. This is called torsional energy or the Torsional resilience.
Torsional energy or strain energy = W.D. by the torque = average torque X angular twist.
= (T/2).θ
= ½.T.θ
= ½. (τ.J/R) (τ.L/R.G)
= ½. (τ2/G).(J/R2).L
= ½ .(τ2/G).[(πD4/32)/(D/2)2].L
= ½ .(τ2/G).(πD2/8).L = ½. (τ2/G).(π.4R2/8).L
= ½. (τ2/G).(π. R2.L/2) = ¼. (τ2/G).Volume
= ¼. (τ2/G).Vor;
U/V = ¼. (τ2/G)

So; Strain energy per unit volume is 1/4th ratio of square of shear stress to modulus of rigidity.
For a hollow shaft : U = [τ2.(D2 + d2)/4.G.D2].Volume of shaft
For a Solid shaft (d = : U = [τ2/4.G].Volume of shaft
very thin hollow shaft (d = 0) : U = [τ2/2.G].Volume of shaft