Flat non-trivial $U(1)$-bundle? Is it possible? maybe this is a very stupid question and I'm missing something very trivial.
It's well known that $U(1)$-bundles are classified by the Euler class or the first Chern class. More precisely, the isomorphism $$c: \check{H}^1 (X, \mathscr{C}^{\infty} (-, U(1))) \xrightarrow{\sim} H^2 (X, \mathbb{Z})$$, induced by the exact sequence $0 \rightarrow \mathbb{Z} \rightarrow \mathbb{R} \xrightarrow{exp} U(1) \rightarrow 0$, the sheaf isomorphism $\mathscr{C}^{\infty} (-, \mathbb{Z}) \cong \mathbb{Z}_X$ and the isomorphism from \v{C}ech to singular cohomology (or de Rham cohomology with integral periods), is the first Chern class or the Euler class. 
It's well known too that the first Chern class is given by $$[\frac{1}{2\pi i}F_{\nabla}]$$. This equality can be accomplished by using that the first Chern class is equal to the Euler class, the global angular form $\psi$ restricts to the Maurer-Cartan form on each fiber and every connection is of the form $\psi + \pi^{*} \alpha$ for some $\alpha \in \Omega^1 (X, \mathfrak{u}(1))$, where $\pi: P \twoheadrightarrow X$ is the $U(1)$-bundle 
1) From these two remarks, one can conclude that if $F_{\nabla} = 0$ on some circle bundle $P$, then $c_1 (P) = 0$ and, therefore, $P$ is trivial. 
However it's well known too that in the theory of Cheeger-Simons  differential characters $$H^1 (X, U(1))$$ classifies flat $U(1)$-bundles with connection by assigning the holonomy $$\text{Hol}_{\nabla} (z) = \langle c, z \rangle$$ for every $z \in Z^1 (X, \mathbb{Z})$ to each $[c] \in H^1 (X, U(1))$ and using the canonical pairing coming from the fact that $U (1)$ is divisible and, hence, $H^1 (X, U(1)) = \text{Hom} (H_1 (X, \mathbb{Z}), U(1))$. 
2) Therefore it may exist non-trivial bundles with flat connection whenever the first cohomology does not vanish.
Having this in mind, why there's a non-trivial flat $U(1)$-bundle? 
In other words, what's wrong in my conclusions in 1 and 2?
Thanks in advance.
 A: This is an answer to your question 1); question 2) is covered in Andrew's answer.
You're mistaking two different characteristic classes. There's the integral first Chern class $c_1(E) \in H^2(M,\Bbb Z)$ and the real first Chern class $c_{1,dR}(E) \in H^2_{dR}(M)$. This last one is the one you calculate with Chern-Weil theory. They're usually not denoted differently. The relation is that, under the canonical map (changing coefficients and then following the de Rham isomorphism), $c_1(E) \mapsto c_{1,dR}(E)$. 
Having a flat connection on a $U(1)$-bundle is equivalent to $c_{1,dR}(E)$ vanishing. You've proved one direction. In the other direction, suppose it vanishes, and that $A$ is a connection on your bundle. I want to find a 1-form $a \in \Omega^1(E \otimes E*) \cong \Omega^1(M)$ such that $da = - F_A$, because of the equation $F_{A+a} = F_A + da$ for connections on a $U(1)$-bundle. Now note that the right hand side is closed by the Bianchi identity; and by your assumption that $c_{1,dR}(E)$ is zero, we see that it must actually be exact. So I can find such an $a$, and therefore my bundle is flat iff $c_{1,dR}(E)$ is torsion.
What's the difference? Torsion classes! Since $M$ is compact we can decompose its second cohomology as $H^2(M;\Bbb Z) \cong \Bbb Z^a \oplus T$, where $T$ is a finite group. That finite group is the group of flat $U(1)$-bundles up to bundle isomorphism, not necessarily preserving the flat connection, because their real first Chern classes vanish.
A: Topological line bundles are classified by $H^1(X, U(1)) \cong H^2(X, \mathbb{Z})$ where $U(1)$ has the usual topology. Flat line bundles are classified by $H^1(X, U(1)) \cong \text{Hom}(H_1(X), U(1))$ where $U(1)$ has the discrete topology; this is often denoted by $U(1)_d$. There's a natural map 
$$H^1(X, U(1)_d) \to H^1(X, U(1)) \cong H^2(X, \mathbb{Z})$$ 
sending a flat line bundle to its first Chern class, and Chern-Weil theory implies that if $X$ is a smooth manifold then this class has image zero in de Rham cohomology. But as Mike Miller says this only implies that it's torsion, not zero. 
A: The Euler class detects topological triviality, not triviality in the finer sense of whether or not a flat connection is a product.
The prototypical example of a flat, non-trivial bundle starts with the product bundle $[0, 1] \times U(1) \to [0, 1]$ equipped with the product connection. If $\theta$ is an arbitrary real number, glue the fibre over $0$ to the fibre over $1$ by rotating through $\theta$; that is, identify $(0, e^{i\phi}) \sim (1, e^{i(\phi + \theta)})$.
The result is a flat, topologically-trivial $U(1)$ bundle $P \to S^{1}$ over the circle. If $\theta \not\in 2\pi \mathbf{Z}$, however, then $P$ admits no covariantly-constant section. When an arbitrary point of $S^{1}$ is removed, the restriction of $P$ to the resulting open interval $I$ is a product bundle $I \times U(1)$ whose covariantly-constant sections are constant maps $I \to U(1)$, and no such section extends continously to a global section of $P$.
In case it's of interest, there similarly exist topologically-trivial holomorphic line bundles over an elliptic curve $E$ that admit no non-trivial global section. For example, let $p$ and $q$ be distinct points of $E$, and let $L$ be the line bundle associated to the divisor $[p] - [q]$. A non-trivial holomorphic section of $L$ would define a meromorphic function $f$ on $E$, holomorphic off $q$ and with a simple zero at $p$ and a simple pole at $q$. Integrating the meromorphic $1$-form
$$
\eta = z \frac{f'(z)\, dz}{f(z)}
$$
around the boundary of a fundamental domain for $E$ and using the fact that the total residue is zero would give $p - q = 0$, which is not the case.
