I've been very interested in turning a fan fiction I did with several other people into a book (and remove all the parts that broke copyright law, leaving only the original story). I have a couple of hurdles though. First, its technically an illegal derivative work. Do my friends and I own the work sans the copyrighted parts, or does the copyright holder own the work. Second, do I need to get my friends to put it into writing that I can profit off of their characters and story, or will a simple "Yes you can do this" over the Internet work? Third, does the person who own the site or server we worked this on own the copyright to the original fan fiction?
There are so many variables here that they don't permit even the semblance of an answer. Your safest bet would be to consult with an intellectual property attorney, who would be able to advise you after analysis of all the specific facts.
Disclaimer: This answer is provided as a public service and as a general response to a general question, it is not meant, and should not be relied upon as specific legal advice, nor does it create an attorney-client relationship.
Intellectual Property Law Attorney
Erik is absolutely right. There is no way to answer to your question w/o more facts -- and even then the answer will not be certain.
It sounds as if you've researched the subject of fan fiction a bit. An article that you may enjoy -- but which will NOT answer your particular questions -- is available at http://tinyurl.com/c6vnfj .
As Erik notes, if you intend to write a book based on a pre-existing work, you will need to discuss the matter with an intellectual property attorney. If you cannot afford one, then call your local law school and ask whether it has a "business clinic" that may help you or reach out to a friendly intellectual property law professor who may lend you a hand.