Can Potential Energy be found by Energy Density? I wanted to find a creative solution to the problem:
Find the electric potential energy of a uniformly charged sphere of radius $R$ possessing a charge $Q$. 
My attempt at a solution:
Consider a gaussian surface, basically a sphere of radius $x$ concentric with the complete charged sphere. Now, by Gauss' Law, $$E(x) \cdot 4 \pi x^{2} = \frac{Qx^{3}}{R^{3}\epsilon_0} \implies E(x) = \frac{Qx}{4 \pi \epsilon_0 R^{3}}$$ Now, let the energy density be represented as $\Omega$. So, $$\Omega(x) = \frac{1}{2} \epsilon_0 E^{2} = \frac{Q^{2}x^{2}}{32 \pi^{2} \epsilon_0 R^{6}}$$ Obviously, $dU = \Omega dV$, and $dV = 4 \pi x^{2} dx$, so $$U = \int_{0}^{U_0}{dU} = \boxed{\frac{Q^{2}}{40 \pi \epsilon_0 R}}$$ 
The problem is, that is not the same answer as I have checked on Internet. Why is my approach wrong? 
Follow up after reading comments: Um, I don't understand. How do you go from here to the answer? $$U = \int_{0}^{U_0}{dU} = \frac{Q^2}{8 \pi \epsilon_0 R^6} \int_{\infty}^{R}{x^4 dx} = \frac{Q^{2}}{40 \pi \epsilon_0 R^6}(R^5 - {\infty}^5)$$ 
What after this?
 A: After reading the comment you have made below, I came to realize that the real deal here is that the electric field is not varying as $x$ outside the sphere. 
The problem here is not the integral (I apologize for that as I did not cross-check). In fact, it seems you are not very clear with the concept of energy density. 
Energy density is the energy per unit volume. What is important for this question is to realise is that you can use the energy density as a function of $x$ as long as it agrees with the value the electric field would have inside the sphere, and then outside the sphere. 
Clearly, as you have derived the E-field is varying directly as $x$ inside. If you apply Gauss' law for a region outside the sphere, you get that the electric field varies as $1/x^2$.
These fields are clearly different in their functional forms. So what you need to do while calculating the potential energy of the sphere is to add the contribution inside and outside the sphere. 
i.e. $ U_1 = \int \Omega_1 dV$ having the limits of $x=0$ to $x=R$ (inside the sphere)
And $U_2 = \int \Omega_2 dV$ having the limits of $x=R$ to $x \to \infty$. 
The required potential energy will be: $U=U_1 +U_2$. You would find that $U_1$ is having a number factor of 1/40 as you have found already. And $U_2$ would have a factor of 1/8. Add them together and you  get $\frac{3Q^2}{20 \pi \epsilon R}$
A: This can be proven. 
Potential energy = $\frac{1}{2}\int VdQ$
$dQ=\rho d\tau$ where $d\tau$ is the volume element. 
So $PE=\frac{1}{2}\int V\rho  d\tau=\frac{1}{2}\int \epsilon_0V(\nabla \cdot \vec{E}) d\tau=\frac{-\epsilon_0}{2}\int V\nabla^2Vd\tau$
This because by Gauss' Law, $\nabla \cdot \vec{E}=\rho/\epsilon_0$
That $\nabla \times\vec{E}=-\frac{\partial \vec{B}}{\partial t}=0$ in Electro statics implies $\vec{E}=-\nabla V$ for some scalar V. 
Now we can invoke a vector identity:
$$V\nabla^2V=\nabla \cdot (V\nabla V)-(\nabla V \cdot \nabla V)$$
So :
$$PE=\frac{-\epsilon_0}{2}\int \nabla \cdot (V\nabla V) d\tau+\frac{\epsilon_0}{2}\int ( \nabla V \cdot \nabla V) d\tau$$
Now by Gauss's Law the first volume integral can be expressed as an area integral over a sphere of infinite radius, but gradient of V is zero infinitely far away. Therefor, the second integral contributes all of the PE.
So $PE=\int \frac{\epsilon_0}{2}E^2 d\tau$
As to why your integrals came out different, they are  very tricky. 
You need to remember the factor of 1/2 when integrating for potential energy. 
Your limits of integration are different as well. Whereas your limits of integration are 0 to R, R being the radius of the sphere for the potential energy, your energy density integral is over all space. Further, the electric field is proportial to $r$, distance from center of the sphere, within the sphere and $1/r^2$ when integrating the density outside of the sphere. 
Sign errors can also be a problem. 
