This was previously a comment to space_cadet's answer but became long (down-vote wasn't me though).
I don't understand space_cadet's talk about unstable orbits. Recall that two-body system with Coulomb interaction has an additional $SO(3)$ symmetry and has a conserved Laplace-Runge-Lenz vector which preserves the eccentricity. Because interactions between planets themselves are pretty negligible one needs to look for explanation elsewhere. Namely, in the initial conditions of the Solar system.
One can imagine slowly rotating big ball of dust. This would collapse to the Sun in the center a disk (because of preservation of angular momentum) with circular orbits and proto-planets would form, collecting the dust on their orbits. Initially those planets were quite close and there were interesting scattering processes happening. The last part of the puzzle is mystery though. If there were still large amount of dust present in the Solar system it would damp the orbits to the point of becoming more circular than they are today. The most popular explanation seems to be that the damping of the eccentricity was mediated by smaller bodies (like asteroids). Read more in "Final Stages of Planet Formation" - Peter Goldreich, Yoram Lithwick, Re'em Sari.
First, Mercury "aligns" with the ecliptic plane only twice in its "year", when it comes from above to below and vice versa.
Luckily for our calculations, Pluto is not a planet any longer, because it would completely rain on our parade with its 248 Earth years of orbital period and another two points within it that it crosses the plane again. Getting Pluto and Mercury aligned alone would take millennia.
Now, what do we count as "aligned"? This is a very vague term because it doesn't state any tolerances. If you mean discs of the planets overlapping, just forget it, their own minor deviations from the ecliptic plane will suffice that it will never ever happen. Let us assume a tolerance of one earth day of their movement. This is fairly generous, in case of Mercury it's over 4% tolerance of its total orbit radius, which considering their size on the sky is quite a lot - in case of all planets the distance traveled over one earth day far exceeds their diameter. So, we're not taking a total alignment, just one night where they are closest to each other, a pretty loose approximation.
Now, we pick the day the rest of the planets are on the plane as Mercury, so let us simply take the 2 in 88 days of its orbital period and continue dividing by orbital periods of other planets.
1 in (44 * 225 * 365 * 687 * 4332 * 10759 * 30799 * 60190) days.
That is one day in $5.8 \cdot10^{23}$ years.
The age of the universe is $1.375 \cdot 10^{10}$ years.
It means planets would align for one day in 42 trillion times the age of the universe.
I think it's a good enough approximation to say it is not possible, period.
Feel free to divide by 365, if you don't want aligned with the Sun but only with Earth. (one constraint removed.) It really doesn't change the conclusion.
Best Answer
The formula $U=mgh$ is simplified and assumes that you are near a planet's surface ($g$ itself is only valid near the Earth's surface). This sounds kind of like a homework problem, so I'll give you some hints. First, you need to pick an origin (usually the star at the center of the system is a good place). Now you need to figure out the forces acting on the planets. Since the problem is asking for gravitational potential energy, you know that you only need to consider gravitational forces. Identify the gravitational forces and then integrate the force along the paths in question to calculate the potential energy. Be sure to maintain the same coordinate system throughout!
Making an assumption about your situation: you might be able to neglect the planet to planet gravitational force if the central force is much larger (which it should be, but I don't know what your problem statement was) and just calculate the potential energy due to the interaction between the planet and the star.
EDIT: I feel i can be more specific --
Gravity, when modeled as a central force (ie, Newtonian gravity) has a value of $F=-G\frac{Mm}{r^2}$, where the different m's are the masses of the two separate objects and r is the distance between them. To find the potential energy due to gravity, you essentially want to calculate the negative of the work done in order to "put" the planet where it is in orbit. Work is just the integral of force from where the potential is defined as 0. In this case, you would need to bring the planet in from $\infty$ where the force vanishes (approaches 0).
So, in math terms, $U=-\int_{\infty}^{r} -G\frac{Mm}{r^{\prime2}} dr^{\prime}=-G\frac{Mm}{r}$. This result is for one planet in relation to the sun, calculated assuming one dimension of force (which is valid for only 2 bodies). If you have more bodies that you want to account for (like other planets), then you need to complicate that expression to higher dimensions and add all the terms from the gravitational forces due to every object with the proper vectors in tact. Luckily, you can use superposition of forces for that so it's not all that messy, but would be a little much here (I think). In practical terms, the gravitational force from the star at the center of a solar system far outweighs that of the individual planets, that you can neglect those terms and come up with a very good approximation of the total gravitational potential.