First, you of course need to assume that $A\neq\emptyset, X$.
Now, the $(\Rightarrow)$ direction in your proof attempt is not correct. Take, for example, the closed interval $[a,b]\subset\mathbb{R}$, which is (as you know ...) path-connected, therefore connected. Put $A=\{a\}\cup\{b\}\subset [a,b]$. Then $A$ is not connected, although $[a,b]$ is connected.
Instead, try to think about what it means for a boundary to be empty. Your intuition is on the right path. Here's how you formalize the $(\Rightarrow)$ direction. Suppose toward contradiction $X$ is connected, but some (nonempty) $A\subset X$ has empty boundary. Then $A$ is closed, because $A = A\cup \partial A$ is its own closure, hence $X-A$ is open. Observe that in $X$, $\partial(X-A) = \partial A$, so we must have that $\partial(X-A) = \emptyset$, hence by the same argument as for $A$ we have $X-A$ is closed, so that $A$ is open. Therefore, $X = A\cup (X-A)$ for two open sets $A$ and $X-A$, and $A\cap (X-A) = \emptyset$, so $A$ and $X-A$ form a disconnect of $X$, contradicting the hypothesis that $X$ is connected.
For the ($\Leftarrow$) direction, how does (2) justify that $\partial A\cap A^c = \emptyset$? Instead, you need to use the hypothesis that $X$ is a metric space, since this direction is not true for a general topological space (take, e.g., the disjoint union of two intervals). Prove the contrapositive: if $X$ is disconnected, then there is some nonempty set $A\subset X$ with $\partial A = \emptyset$. Your intuition is again correct that $A$ will be one of the disconnecting sets. By the argument above, $X = A\cup B$ for two disjoint clopen sets $A$ and $B$. But now you're done: $A \supset \partial A = \partial B \subset B$, which tells you that $\partial A = \partial B = \emptyset.$
For the first part of the proof the fact that $f[X]$ is open in $\Bbb Z$ is irrelevant: all that matters is that the only non-empty, connected subsets of $\Bbb Z$ are the singletons.
The other direction is fine, though it can be done more simply without the pasting lemma. Just prove the contrapositive. If $X$ is not connected, there is a continuous function $f$ mapping $X$ onto the discrete two-point space $\{0,1\}$. Clearly this $f$ can be viewed as a continuous function from $X$ to $\Bbb Z$, and it is not constant.
Best Answer
It is straightforward, using the definition of continuity and connectedness to show that if $f(X)$ is not connected, then $X$ is not connected. That is, if $f(X) = W \cup Z$ where $W,Z$ are two non empty disjoint open sets, then $f^{-1}(W), f^{-1}(Z)$ are two non empty disjoint open sets whose union equals $X$. This proves one direction.
If $X$ is disconnected, then there are two non empty disjoint open sets $U,V$ such that $X=U\cup V$. Define $f(u) = 1$, for $u \in U$ and $f(v) = 0$ for $v \in V$. Since $f(X)$ is not connected you have shown the other direction.
Addendum: To show that $f$ is continuous, we need to show that $f^{-1}(W)$ is open for all open $W \subset \mathbb{R}$. There are only four cases to consider (1) $\{0,1\} \subset W$, in which case $f^{-1}(W) = X$, (2) $ 1 \in W, 0 \notin W$, in which case $f^{-1}(W) =U$, (3) $ 0 \in W, 0 \notin W$, in which case $f^{-1}(W) =V$ and (4) $\{0,1\} \cap W = \emptyset$, in which case $f^{-1}(W) = \emptyset$.
In all cases, $f^{-1}(W)$ is open, hence $f$ is continuous.