Okay, okay. Some things first.
There is difference between copying, plagiarism and inspiring.
For general rule copying is bad, but if you are talking only about the general idea of the story, there is no problem. Because there is no new ideas, really. You can add new elements, change some characters, but most ideas are already out there, and you can find a lot of examples like that out there. Heck, even the Bible is a copy of another stories.
BUT if you take too much inspiration, and we can't separate your idea from the one from another person, if there has no been permission, you are doing plagiarism, and that's bad. If you think that you are doing something extremely close to the original idea, you must have permission before publishing (any way of publishing, it is open to public, it is considered published). This is a must if you charge for your story.
If your story is free, and you are not damaging whatsoever the original product, it can be considered fair use. This is most plausible if the original story its from a big author that will not even open a mail from you asking for permission. Most derivative works are okay, as long as you do the crediting.
Hope this quick advise had clarified some of your doubts n_n