Energy calculation in frequency domain
You need Parseval's theorem. For the discrete-time Fourier transform (DTFT) you have the following relation:

$$\sum_{n=-\infty}^{\infty}|x[n]|^2=\int_{-1/2}^{1/2}|X(f)|^2df\tag{1}$$

where $f$ is normalized by the sampling frequency. For the DFT you have

$$\sum_{n=0}^{N-1}|x[n]|^2=\frac{1}{N}\sum_{k=0}^{N-1}|X[k]|^2$$

So due to Parseval's theorem it is always possible to compute a signal's energy in the time domain as well as in the frequency domain.