You have to look for particular matrices B which allow you to get information on A.
Taking as B the matrix with $B_{1,1}=1$ and zeros everywhere else, you can notice that $AB$ is the matrix with the first column equal to that of A and the other cells equal to 0, while $BA$ is the matrix with the first row equal to that of A. So, the first row and the first column of A must be 0 except for the diagonal element. Repeating this reasoning for every $i=0,...,n$, we get the matrices B of the type $B_{i,i}=1$ and other entries equal to $0$, so we get that A must be diagonal.
Now, let $(a_1,...,a_n)$ be the diagonal of A. We know that $AB$ is the matrix which $i$-th row is given by $a_iB_i$, where $B_i$ is the $i$-th row of $B$.
Regarding $BA$, we know that its $i$-th column is $a_iB^i$, where $B^i$ is the $i$-th column of $B$; so, its rows are given by the component-wise product of $(a_1,...,a_n)$ and the rows of $B$. So, we have:
$$\forall \ i=1,...,n \ \ (a_1b_{i,1},...,a_nb_{i,n}) = (BA)_i = (AB)_i = (a_ib_{i,1},...,a_ib_{i,n}) $$
and this must holds for each matrix B, which implies that $a_i=a_j \ \forall \ i,j =1,...,n$.
So, we can conclude that the matrix you are looking for are that of the form $\lambda I$ for $\lambda \in \mathbb{R}$, where $I$ is the identity matrix. This clearly is a vector space since it is just the span of the matrix $I$.