The other answer is right, but I find it a little hard to read. Here is my attempt to clarify.
The total amount of energy never changes. It just moves between three compartments: gravitational potential energy, spring potential energy, and kinetic energy.
Two of these compartments have natural zeros: kinetic energy is zero when the block isn't moving, and spring potential energy is zero when the spring is not compressed. But when it comes to the third compartment--gravitational potential energy--you get to choose where zero is. In your answer, you have chosen it to be zero when the block first touches the spring: that's how you get $PE_i=mgh$.
Since kinetic energy is zero when the block reaches its lowest point, all the energy at that point is in the other two compartments. The spring potential energy, as you surmise, is $\frac{1}{2}kx^2$, but the gravitational potential energy is not zero--you already decided that it's zero when the spring is uncompressed. Since you've moved down from that point by a distance $x$, the gravitational potential energy is negative: it's $-mgx$.
So, $$PE_i = PE_f \implies mgh = \frac12kx^2 - mgx.$$