What is the main idea of this story?
It seems to me that the main idea or theme is implied rather than stated in specific terms. That idea or theme has to do with important truths about life, and the magic bottle itself, which is something we would all like to have, is a device for catching and holding our interest. The story is telling us that money can't buy happiness and the things that it can buy are mostly trivial because we can't keep them. Money can't buy a longer life. The threat of hell that haunts the story is really the universal human fear of death. What is important in life, according to Stevenson, is love. The husband and wife are both willing to sacrifice themselves for each other. That is something money can't buy either. The idea of the bottle having to be sold for less than the owner paid for it symbolizes the truth that time is always running out for all of us. Material things mean less and less as we grow old, just as the bottle is worth less and less with the passing of time and the changes of ownership. All material things pass from owner to owner when people die, and usually they are worth less and less, until they can't even be given away.
[Robert Louis Stevenson suffered from bad health for most of his life, and his many years of travels were partly motivated by the desire to find a climate that was favorable to his constitution. The Wikipedia article on Stevenson says that he was thought to have tuberculosis but that the diseae may have been bronchiectasis or sarcoidosis. He was haunted by the fear of death, and that fear is expressed metaphorically in his story "The Bottle Imp." The magic bottle is symbolic of life itself. For every day we live, there is one day subtracted from the amount of time we have left to enjoy life. The magic bottle might be regarded as the magic power that inspired Stevenson to write his stories, poems, and novels. He died in Tahiti when he was only forty-four years old. At that time he was one of the most famous writers in the world. The Wikipedia article quotes his famous "Requiem," the last two lines of which are inscribed on his tombstone.]
Under the wide and starry sky,
Dig the grave and let me lie.
Glad did I live and gladly die,
And I laid me down with a will.
This be the verse you grave for me:
Here he lies where he longed to be;
Home is the sailor, home from sea,
And the hunter home from the hill.