$\sum_i (x_i-\bar{x})(y_i-\bar{y}) = \sum_i \left(x_iy_i - \bar{x}y_i - x_i\bar{y}+\bar{x}\bar{y}\right)$
$=\sum_i(x_iy_i)-\sum_i(\bar{x}y_i)-\sum_i(x_i\bar{y})+\sum_i(\bar{x}\bar{y})$
Now... recognize that the terms $\bar{x}$ and $\bar{y}$ are in fact just constants and so may be factored outside of their respective summations
$=\sum_i(x_iy_i)-\bar{x}\sum_i(y_i) - \bar{y}\sum_i(x_i) + \bar{x}\bar{y}\sum_i(1)$
Recall that $\sum_{i=1}^n(1)=n$. Next, recall that $\bar{x}=\frac{1}{n}\sum_i(x_i)$ and similarly for $\bar{y}$. Rearranging a bit by multiplying both sides by $n$ we get that $\sum_i(x_i)=n\bar{x}$ so we continue as:
$=\sum_i(x_iy_i)-n\bar{x}\bar{y} - n\bar{x}\bar{y}+n\bar{x}\bar{y}$
One pair of these cancel, and rewriting $\bar{x}$ and $\bar{y}$ as sums instead gives us
$=\sum_i(x_iy_i)-n(\frac{1}{n}\sum_i(x_i))(\frac{1}{n}\sum_i(y_i))$
$=\sum_i(x_iy_i)-\frac{1}{n}(\sum_ix_i)(\sum_iy_i)$ as desired
The second identity involving only $x$'s is exactly the same as the first identity, just using $x$'s in place of $y$'s and simplifying with exponents where necessary.