First, I consider this expression to find the work done by the weight over an object close to Earth's surface: $$W_{over\ object}=\int_{\vec{y_{1}}}^{\vec{y_{2}}}\vec w \cdot d\vec y$$ $$W_{over\ object}=\int_{\vec{y_{1}}}^{\vec{y_{2}}}-mg \hat{\textbf{j}} \cdot d\vec y$$ I'm assuming both the force and displacement are in the same direction, downwards, and I develop the dot product and get the next expression: $$W_{over\ object}=\int_{y_{2}}^{y_{1}}mgdy$$ Because it's going downwards ($y_{2}<y_{1}$), I thought it was a good idea to switch the integration limits since the expression is a scalar now, so that the upper limit is the highest value for the integration variable. Then I get this: $$W_{over\ object}=mgy_{1}-mgy_{2}$$
Because of Newton's third law, I may find the work done by the object over the thing that does work over the object, which is Earth (I guess): $$W_{over\ Earth}=\int_{\vec{y_{1}}}^{\vec{y_{2}}}-\vec w \cdot d\vec y$$ $$W_{over\ Earth}=\int_{\vec{y_{1}}}^{\vec{y_{2}}}+mg \hat{\textbf{j}} \cdot d\vec y$$ Again, I assume displacement is downwards, thus $y_{2}<y_{1}$: $$W_{over\ Earth}=\int_{y_{2}}^{y_{1}}-mgdy$$ $$W_{over\ Earth}=-mgy_{1}+mgy_{2}$$ If we let $U_{1}=mgy_{1}$ and $U_{2}=mgy_{2}$, we have: $$W_{over\ object}=-W_{over\ Earth}=U_{2}-U_{1}=\Delta U$$
In order to make this scenario more general: $$F_{over\ object}dx=W_{over\ object}$$ $$-F_{over\ object}dx=-W_{over\ object}=dU$$ $$F_{over\ object}=-\frac{dU}{dx}$$ Changing notation a bit: $$F(x)=-\frac{dU(x)}{dx}$$
After all this, what I've done seems to work, but I don't think it's rigorous at all. How can I approach this kind of problem more appropriately? More specifically, how can I treat an integral where the integrand is a vectorial function (namely, a force function), and the variable of integration is a vector as well? I think the core of my problem is treating the dot product itself when integrating, in order to find the work done by a conservative force function over a displacement interval and its associated potential energy function, with a vectorial approach.
In this sense, I have doubts regarding the derivation of the potential energy function for this particular case and how to obtain it by using a more mathematically rigorous approach.