We analyze statistical arbitrage with pairs trading assuming that the spread of two assets follows a mean-reverting Ornstein-Uhlenbeck process around a long-term equilibrium level. Within this framework, we prove the existence of statistical arbitrage and derive optimality conditions for trading the spread portfolio. In the existence of uncertainty in the long-term mean and the volatility of the spread, statistical arbitrage is no longer guaranteed. However, the asymptotic probability of loss can be bounded as a function of the standard error of the model parameters. The proposed framework provides a new filtering technique for identifying best pairs in the market. Backtesting results are given for some of the pairs of stocks that are studied in the literature.