In Newtonian mechanics, energy arises from the line integral of the second law along the object's path:
$\Sigma_i\overrightarrow F_i = m\overrightarrow a
= m\frac{d\overrightarrow v}{dt}\\
\int (\Sigma_i\overrightarrow F_i) \cdot d\overrightarrow r
= \int m \frac{d\overrightarrow v}{dt} \cdot d\overrightarrow r\\
\Sigma_i \int \overrightarrow F_i \cdot d\overrightarrow r
= m\int d\overrightarrow v \cdot \frac{d\overrightarrow r}{dt}$
That last step on the right-hand side is a key concept: we can move the $dt$ from $d\overrightarrow v$ to $d\overrightarrow r$, because the change in velocity and change in position happen during the same time interval -- all three differentials correspond to the same little piece of the path. Also, on the left-hand side, we simply define the work done by a force as $\int\overrightarrow F\cdot d\overrightarrow r$, so we have:
$\Sigma_i W_i = m\int d\overrightarrow v\cdot \overrightarrow v$
Now the other key point: $d\overrightarrow v \cdot \overrightarrow v$ is the differential of $\frac12 \overrightarrow v \cdot \overrightarrow v = \frac12 v^2$. So
$\Sigma_i W_i = m\Delta(\frac12 v^2)$
Likewise, we define kinetic energy as $K = \frac12 mv^2$. That makes intuitive sense: the more massive an object is and the faster it's moving, the more motion energy it has.
$\Sigma_i W_i = \Delta K$
That's the work-energy theorem: the sum of the works done by all forces gives the change in kinetic energy.
Now, for a given force, that line integral will in general depend on the path the object takes. But oddly, it turns out that the fundamental forces of nature, such as gravity and the electric force, do the same amount of work for any path between two given points. So we don't need to do the integral every time. We just need a formula for the work they will do, in terms of the two endpoints.
$W = W(\overrightarrow r_i, \overrightarrow r_f)$ for a path-independent force
But we can also think of that work as the kinetic energy the object stands to gain by moving from $\overrightarrow r_i$ to $\overrightarrow r_f$. So we call that the potential energy of $\overrightarrow r_i$ relative to $\overrightarrow r_f$:
$U(\overrightarrow r_i) - U(\overrightarrow r_f) = W(\overrightarrow r_i, \overrightarrow r_f)\\
U(\overrightarrow r_f) - U(\overrightarrow r_i) = -W(\overrightarrow r_i, \overrightarrow r_f)\\
\Delta U = -W$
So the potential energy difference has the opposite of the kinetic energy difference: for a path-independent force, the object loses the same amount of potential as it gains kinetic, by virtue of our definition. Which means that if you add the potential and kinetic just due to that force, they remain the same.
Therefore, you can take the work-energy theorem above, and replace the work terms in the sum by potential energy changes - but only for those forces that have potential energy, ie. path-independent forces:
$\Sigma_i W_i = \Delta K\\
\Sigma_{path-independent}(-\Delta U_i) + \Sigma_{path-dependent}W_i = \Delta K$
Now, if all forces do path-independent work, we have:
$\Sigma_i(-\Delta U_i) = \Delta K\\
-\Delta U_{total} = \Delta K\\
\Delta U + \Delta K = 0\\
\Delta(U + K) = 0$
That is, total mechanical energy is conserved. Therefore, we call those path-independent forces conservative forces.
So that's mechanical energy in a nutshell. But as to your problem, it actually goes back to that definition of work, because it's the integral of the dot product. At all points along your path, gravity is pointing toward the second object's COM, and so is the displacement of the first object. Since those two vectors have the same direction, their dot product is positive, not negative. So your work will come out positive.
The intuition behind the work formula is that, when you push an object and it moves the direction you're pushing it, you are contributing to the accomplished motion, so you're doing positive work. But if someone else pushes harder, and it moves against your push, you're hindering the process, hence doing negative work. The harder you pushed and the further it moved, the more work you did.
So, like you said, mathematically, energy is just a set of definitions on top of the second law - but those definitions match the intuitive understanding of the terms, and the math gives us shortcuts to solving problems.
EDIT: Note I said it was "odd" that the fundamental forces of nature are path-independent, ie. conservative. But, in retrospect, that fact suggests that energy is actually a very natural concept in physics, perhaps more so than force. The derivation from force is slightly awkward, but energy conservation is a much more universal principle (even if it's not quite as strict in modern physics).