What the OP has given as the electric fields inside and outside the sphere are only the magnitudes of these fields, as has been emphasized in other comments and answers. I suspect that those expressions were derived using Gauss' Law, which relied on spherical symmetry to assume two things: (i) that the field at a point with position vector $\vec{r}$, a distance $r = |\vec{r}|$ from the center of the sphere, depended only on this distance, and (ii) that the field was directed radially outward from the center of the sphere along the unit vector $\hat{r} = \vec{r}/r$. So the electric field vector is a piecewise continuous function of the radial coordinate $r$ alone, with direction $\hat{r}$, given by
$$\begin{align}\vec{E}(r) \,=\, \begin{cases}~~\vec{E}_{in}(r) = \dfrac{q}{R^3}\,r\,\hat{r}, ~~~ r \leq R, \\ \\~~ \vec{E}_{out}(r) = \dfrac{q}{r^2}\,\hat{r}, ~~~ r \geq R, \end{cases}\end{align}$$ where I am writing $$q = \dfrac{Q}{4\pi\epsilon_0}$$ for convenience. Since $\vec{E}(r)= -\nabla \phi(r)$ depends only on the radial coordinate $r$, it reduces to $$\vec{E}(r) = -\dfrac{d\phi}{dr}(r)\,\hat{r}.$$ The negative derivative of the scalar function $\phi(r)$ with respect to $r$ thus gives the radial (and only) component of $\vec{E}$, so from the piecewise expressions for the electric field we find the piecewise expressions for the derivative of $\phi$: $$\begin{align}-\dfrac{d\phi}{dr} = \begin{cases}~~\dfrac{q}{R^3}\,r, ~~~ r \leq R, \\ \\~~ \dfrac{q}{r^2}, ~~~ r \geq R, \end{cases}\end{align}$$ The indefinite integral of each side in the two cases gives $$\phi(r) = -\int\dfrac{q}{R^3}\,r\,dr = - \dfrac{q}{R^3}\dfrac{r^2}{2} + C_1, ~~~~r \leq R,$$ and $$\phi(r) = -\int\dfrac{q}{r^2}\,dr = \dfrac{q}{r} + C_2, ~~~~r \geq R.$$ In the second expression with $r \geq R$, in order for the potential to vanish as $r \to \infty$, we must set the integration constant $C_2 = 0$, hence $$\phi(r) = \dfrac{q}{r}, ~~~~r \geq R.$$ In order for the potential to be continuous at $r = R$, the potentials must be equal at the boundary: $$-\dfrac{q}{R^3}\dfrac{R^2}{2} + C_1 = \dfrac{q}{R},$$ from which we find $$C_1 = \dfrac{3q}{2R}.$$ The scalar potential is thus given by the piecewise continuous function $$\begin{align}\phi(r) \,=\, \begin{cases}~ -\dfrac{q}{R^3}\dfrac{r^2}{2} + \dfrac{3q}{2R}, ~~~r \leq R,\\ \\~~ \dfrac{q}{r}, ~~~r \geq R.\end{cases}\end{align}$$ In terms of $q = Q/4\pi\epsilon_0$, these are $$\begin{align}\phi(r) \,=\, \begin{cases}~~-\dfrac{Q}{8\pi\epsilon_0 R^3}\,r^2 + \dfrac{3Q}{8\pi\epsilon_0 R}, ~~~r \leq R,\\ \\ ~~\dfrac{Q}{4\pi\epsilon_0 r}, ~~~r \geq R.\end{cases}\end{align}$$
If $\vec{g}=\left[\begin{array}{c}f_1\\\vdots\\f_m\end{array}\right]$ then the derivative of $\vec{g}$ is the matrix
$$J\vec{g}=\left[\begin{array}{c}\nabla f_1\\\vdots\\\nabla f_m\end{array}\right],$$
which is an $m\times n$ - rectangular array.
In components, you would see it as
$$J\vec{g}=\left[\dfrac{\partial f_i}{\partial x_j}\right],$$
where $i$ is for rows and $j$ is for columns, and where $x_1,...,x_n$ are the standard coordinate functions of $\Bbb R^n$.
Best Answer
The notation $M = \int \vec F\cdot d\vec r$ elides an important detail: the path along which $F$ is to be integrated. The usual construction is to integrate along a path that starts at a fixed point $p$ and ends at a variable point $x$. But there are two trouble spots with this construction.
The first is not so bad. How do we know that there is a path from $p$ to each point $x$? So we have to add the assumption that the domain of $\vec F$ is connected, or technically path-connected. If the domain is connected, we at least have an $M(x)$ for each $x$.
The second is trickier. $M$ needs to be a function, and it should depend only on $x$, not on the specific path one takes from $p$ to $x$. Otherwise you and I could accidentally pick different paths and get different results, and we wouldn't know which one to call $M(x)$. So $\vec F$ needs the property that line integrals are independent of path. This is equivalent to the property that line integrals around closed loops are zero.
If line integrals around closed loops are zero, it follows from Stokes's theorem that $\nabla \times \vec F = \vec 0$. And the implication almost goes in the other way, too, except for the possibility that the path wraps around a “hole” in the domain. Try $$ \vec F(x,y,z) = \left<- \frac{y}{x^2+y^2}, \frac{x}{x^2+y^2},0\right> $$ Then $\nabla \times \vec F = \vec 0$. However, the domain of $\vec F$ excludes the $z$-axis, where $x=y=0$. And in fact, if we integrate $\vec F$ around the unit circle in the $xy$-plane, we get $2\pi$, not $0$. So this $\vec F$ is not conservative, despite it having a curl of zero.
So we rule out that possibility and require that the domain of $\vec F$ be not just connected but simply connected: that any closed loop in the domain is contractible to a point. Picture a slipknot closing up. If the domain has no holes, a loop in the domain can contract to a point, but if there is a hole, a loop around that hole can't move “past” it.
So if $\vec F$ has a curl of zero, and the domain of $\vec F$ is connected and simply connected, your construction does result in a potential function and proves that $\vec F$ is conservative.
It's worth noting that the sufficient conditions are not just differential ($\nabla \times \vec F = \vec 0$), but topological (domain is connected and simply connected). To follow this point, if we have a domain and we want to know more about its shape, we might try to construct vector fields with zero curl but which aren't conservative. If we could find one, we would know the domain is not simply connected. This kind of study is called algebraic topology.