You can use anything in the public domain for any purpose. But if a fairy tale is still under copyright, or if the character is trademarked, then only the rightsholder owns the exclusive right to, respectively, make "derivative works" from an earlier work, and use the trademark, you intend to do.
You should consult with an IP lawyer to check which works to want to use to make sure you can use them for your stated purpose.
Disclaimer: Please note that this answer does not constitute legal advice, and should not be relied on, since each state has different laws, each situation is fact specific, and it is impossible to evaluate a legal problem without a comprehensive consultation and review of all the facts and documents at issue. This answer does not create an attorney-client relationship.
Ms Koslyn's answer is spot on.
Think of it this way: your book would not make any sense, or have much commercial value, were it not for the stories created by other writers. You are building upon those other works and so, if those other works are still under copyright, only the copyright owner of the works has the right to extend the story lines.
That being said, a great many fairy tales are in the public domain. If you want to extend those story lines, you may. Read the ORIGINAL story and be very careful not to include any details in your book that were added by writers who themselves re-wrote the original story. For example, only the Disney version of Snow White gave names to the Seven Dwarfs (so you cannot use those names).