The basic fact we use is the one you start out with (which I won't prove, as I assume it's already known; it's not hard anyway):
(1) $X$ is connected iff every continuous function $f: X \rightarrow \{0,1\}$ (the latter space in the discrete topology) is constant.
So, given connected spaces $X$ and $Y$, we start with an arbitrary continuous function $F: X \times Y \rightarrow \{0,1\}$ and we want to show it is constant. This will show that $X \times Y$ is connected by (1).
First, for a fixed $x \in X$, we can define $F_x: Y \rightarrow \{0,1\}$ by $F_x(y) = F(x,y)$.
This is the composition of the maps that sends $y$ to $(x,y)$ (for this fixed $x$) and $F$, and as both these maps are continuous, so is $F_x$, for every $x$. So, as this is a continuous function from $Y$ to $\{0,1\}$ and $Y$ is connected, every $F_x$ is constant, say all its values are $c_x \in \{0,1\}$.
Of course we haven't used the connectedness of $X$ yet, so we do the exact same thing fixing $y$: for every $y \in Y$, we define $F^y: X \rightarrow \{0,1\}$ by $F^y(x) = F(x,y)$. Again, this is a composition of the map sending $x$ to $(x,y)$ (for this fixed $y$) and $F$, so every $F^y$ is continuous from the connected $X$ to $\{0,1\}$ and so $F^y$ is constant with value $c'_y \in \{0,1\}$, say.
The claim now is that $F$ is constant: let $(a,b)$ and ($c,d)$ be any two points in $X \times Y$. Then we also consider the point $(a,d)$ and note that:
$$F(a,b) = F_a(b) = c_a = F_a(d) = F(a,d) = F^d(a) = c'_d = F^d(c) = F(c,d)\mbox{,}$$
first using that $F_a$ is constant and then that $F^d$ is constant. We basically connect any 2 points via a third using a horizontal and a vertical "line" (here via $(a,d)$) and on every "line" $F$ remains constant, so $F$ is a constant function. This concludes the proof.
As a last note: the fact that a function $x \rightarrow (x,y)$, for fixed $y$, is continuous, is easy from the definitions: a basic neighbourhood of $(x,y)$ is of the form $U \times V$, $U$ open in $X$ containing $x$, $V$ open in $Y$ containing $y$, and its inverse image under this function is just $U$.
U can easily show that:
$[0,1]\subset \mathbb R$ can not be written as countable union of closed and disjoint sets $\implies $ $\mathbb N$ with the cofinite topology is not patch-connected
Prove: If $\mathbb N$ where patch-connected then there is a continuous map $\gamma :[0,1] \rightarrow \mathbb N$ such that $\gamma(0)=x$ and $\gamma(1)=y$ for all x,y $\in \mathbb N$. Then $[0,1]=\gamma^{-1}(\mathbb N)=\gamma^{-1}(\bigcup_{i=1}^{\infty}\{i\})=\bigcup_{i=1}^{\infty}\gamma^{-1}\{i\}$ Since finite elements in the confinite topology are closed and $\gamma$ is continuous we have a countable union of closed disjoints sets. A contradiction.
Now it is enough to prove that there does not exist such an union.
Here is the basic idea: (Again by contradiction)
1) Suppose that $\bigcup_{i=1}^{\infty}B_n=[0,1]$ with closed and disjoint $B_n$
2) Construct a decreasing sequence of closed intervals $...I_4 \subset I_3 \subset I_2 \subset I_1 \subset [0,1]$ such that $B_n \cap I_n =\emptyset$
3) The set $\bigcap_{n=1}^{\infty}I_n$ is not empty. Let $x$ be an element of the set. Then $x$ is element of every $I_n$ and of exactly one $B_n$, hence $B_j \cap I_j=\{x\}$ for one $j\in \mathbb N$. A contradiction. The statement follows.
I left the construction of the intervals $I_n$ by the reader :)
Best Answer
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.