The extension will be
Note quite what you asked, but related:
Continuous extensions of (continuous) functionals from $M$ are unique if and only if $M$ is a dense subspace of $X$. Otherwise its closure is a proper closed subspace and therefore there exists a nonzero linear bounded functional $\phi$ vanishing on the closure, which implies that $F+\phi$ is bounded and also extends $f$.
For the second question, it is easier to put conditions on $M$ so that for every $Y$, every map from $M$ to $Y$ can be extended. As mentioned in the comments, a necessary and sufficient condition is that $M$ is a complemented subspace of $X$.

