On the inverse of block tridiagonal matrices with applications to the inverses of band matrices and block band matrices