Here is a way to generate such matrices, by starting from infinite-dimensional spaces.
Let $k$ be a field and consider the vector space $ V = k[x]$ of polynomials in one variable over $k$.
We have two nice linear maps from $V$ to itself, namely $D: V\to V$ which is differentiation, and $M:V\to V$ which is multiplication by $x$.
Now we note that $DM - MD$ is the identity on $V$, so we now have our example when working in an infinite-dimensional space.
To get an example in case $k$ has characteristic $p$ and the space has dimension divisible by $p$ (i.e. we want $np\times np$ matrices $A$ and $B$ for some $n$ such that $AB - BA = I$), we note that the subspace $W$ of polynomials divisible by $x^p$ is invariant under both $D$ and $M$ (for $M$ this is obvious and for $D$ this is because we are in characteristic $p$, so $D(x^p) = 0$).
Thus, on the quotient $V/W$ we get linear maps $\overline{D}$ and $\overline{M}$, which precisely satisfy that $\overline{D}\overline{M} - \overline{M}\overline{D} = I$ as we wanted.
This gives us $p\times p$ matrices. To get $np\times np$ matrices, we simply put $n$ copies of these matrices into the diagonal.
I leave it as an exercise for the interested reader to actually write up the matrices found in this way.