Get a license.
The only way that is surefire to not get into trouble for making a fan product is to get a license for the use of the copyrighted material.
Some companies give (partial) licenses easily and freely, such as Wizards of the Coast offers with the OGL.
Others are litigious and shut down fan projects regularly. Nintendo has the nickname Nintendon't for a reason.
But... fair-use?
...is an affirmative defense. If you have to explain to someone how your work is supposed to be Fair Use, you already are in trouble. Some projects are fair use, others aren't. Many cases are fair use, and many more aren't. If that goes to court, such cases are a gamble, unless your use is quintessential fair use. Few are. A license circumvents the problem.