If I reworked an idea published by a paper which has a fatal error, could I publish a paper on my work?
Sure, if your results are watertight you should publish them. When you point out the shortcommings of the previous paper, you have to do it with extreme tact. Ask somebody knowledgeable in the area of work, probably your advisor or respected faculty, to go over that particular part of your text (at least) before sending it out for review, and be specially careful with any suggestions in that area.