Fluctuation method for calculation of elastic constants of solids