First of all, we know that the area with $x$-axis of the graph of any function $f(x)$ from $x=a$ to $x=b$ is equal to $\int_a^b \! f(x) \, \mathrm{d}x$.
Simmilarly, the area with $x$-axis of the graph of another function $V=f(Q)$ from $Q=0$ to $Q=Q$ is equal to $\int_0^Q \! f(Q) \, \mathrm{d}Q = \int_0^Q \! V \, \mathrm{d}Q$.
In the case of a capacitor, the Voltage is $0$ at first and it rises as the following equation: $V=\frac{Q}{C}$ until it becomes equal to the voltage of the battery.
The equation can be represented as $y=mx$ (the equation of a straight line intersecting the $(0,0)$ point). Here, $V=y$, $\frac{1}{C}=m$ and $Q=x$.
Let us replace $x$ and $y$ with $Q$ and $V$:
Here the graph generates a triangle with the $x$-axis. The final voltage of the capacitor is equal to the voltage of the battery, $V$.
So, we can easily find out the area of the triangle which is,
$$\frac{1}{2}(Q-0)(V-0) = \frac{1}{2}QV$$
And, it is U. Because, $\int_0^Q \! V \, \mathrm{d}Q = U$ (now you can look at the first 2 lines if you don't understand why it is equal to the Area). Thus,
$$U=\frac{1}{2}QV$$
Now, let us discuss the battery.
The voltage of the battery remains constant and thus the graph is parallel to the $x$-axis. So, it generates a rectangle with the $x$-axis. Here is the graph of a constant function:
And the area will be $\text{length}\times\text{breadth}$.
In our case, it is $(Q-0)\cdot(V-0)=QV$
And it is $W$. Thus,
$$W=QV$$
Summary of the answer: We can say that the energy of the capacitor is lower because most of the time, the voltage of the capacitor is lower than the battery (so, the upper left part of the graph is missing in the case of the Capacitor which is present in the Battery).
If you understand nothing from the above writing, look at the image below:
But the question is, where is the rest half?
The answer is, the rest half of the energy is converted to heat because of the resistance of the wire.