So you have your equation of motion about the static equilibrium position $\ddot x = - \omega_o^2 x $ with a simple solution $x=A \sin (\omega_o t) $ and $\dot x=A \omega_o \cos (\omega_o t) $ where $x$ is the displacement of the mass $m$ from the static equilibrium position and $\omega_o^2 = \frac k m$ where $k$ is the spring constant.
The static equilibrium condition is $mg-ky_o = 0$ where the extension of the spring is $y_o$.
Also if the extension of the spring is $y$ then $y=x+y_o$.
To consider energy one needs to define the system.
The system could be the mass alone, the spring and the mass, or the spring, the mass and the Earth.
The last of these in the only system which allows you to use gravitational potential energy $”= mg \Delta h”$ assuming that the Earth’s mass is much greater than the mass at the end of the spring and this is the system that is going to be considered.
Assume that the zero of elastic and gravitational potential energy is when the spring is unextended.
When the mass is at a displacement $x$ from the static equilibrium position then, using $mg-ky_o = 0$, the sum of the elastic and potential energies is
$\frac 1 2 k (x+y_o)^2 -mg(x+y_o) = -\frac 1 2 ky_o^2 + \frac 12 k x^2$.
So at any instant the total energy of the system (mass, spring and Earth) is
$-\frac 1 2 ky_o^2 + \frac 12 k x^2 + \frac 12 m\dot x^2$.
$\frac 12 k x^2 + \frac 12 m\dot x^2 = \frac 12 m \omega^2 A^2$ and this is the energy associated with the simple harmonic motion, which is constant.
Then one has to add a constant term $-\frac 1 2 k y_o^2$ to get the total energy of the system to show that the energy of the system is constant.