As I understand, J.K.Rowling owns right for characters, story, special words (like "muggle"), and so on. Warner Bros. has exclusive right to make movies based on the original books/stories.
Here is a discussion on acquiring a license to produce Harry-Potter-related products. But what about movies, based on alternative stories in the same universe with the same characters?
I imagine that one can just ask J.K.Rawling for her permission to make a movie based on a fanfic. Since it is not an original book/story, which can be filmed only by Warner Bros, it means that one can make a deal to produce a movie based on fanfic, and pay, say, 80% of revenue to the author, if author is agreed :)
But I suppose this only possible in the ideal world.