How does one measure what causes earthquakes? I know that they occur when energy that was previously stored is released in seismic waves. But how is the energy stored in the earth in the first place, and what can trigger the release of such energy?

Put another way, the above preconditions for earthquakes can be brought about by natural phenomena such as fault lines in the earth, and also by man-made phenomena such as mining. What are the ways to measure/estimate the "potential" energy of a fault line, and the likely resulting earthquake, and what are the ways to measure/estimate the energy released by mining or other human activities, and how large an earthquake is likely to result?
There are a number of causes (this list is probably not complete):


Elastic Rebound of tectonic faults. This is the most common and well known. Here the energy is elastic energy stored as two blocks of rocks move against each other. There is a point where elastic deformation cannot take up the entire movement, and the rock breaks releasing the elastic energy. This is better explained here: Reid's Elastic Rebound Theory (USGS)
Landslides/etc. These typically appear as extremely shallow earthquakes and can often be determined from seismic records.
Cavity collapses. E.g. mines, volcanic systems, caves.
Subterranean explosions / volume expansion. Eg. mining activity, atom bomb tests, volcanic activity (eg. phreatic involving water; or magma injection)
Crystalline phase changes. Fast, deep subduction zones (eg. Tonga) experience very deep earthquakes where the rocks should be too plastic for classic elastic rebound. These are usually interpreted as 'catastrophic' phase changes of olivine -> spinel -> perovskite, and the depths generally match. Eg. Kirby 1991.