Literature (and other forms of storytelling) tend to tell the same basic plots in many different ways, to the point that scholars of literature attempt to condense them down into things like ‘seven basic plots’ (Christopher Booker).
Some stories are passed down to us from many thousands of years before copyright limitations, and you can write based on those as freely as you want: myth, old fairy tales, heroic epics… Shakespeare wrote before anyone was worried much about copyright, and he’s certainly old enough you could return the favor.
Stories that use the model of another great story as a homage to it are also rather common. Virgil’s Aeneid is a love letter to the Illiad and the Odyssey, jumping off from the same event (the Trojan War) and using a similar structure to give Rome its own great epic. Retellings of A Christmas Carol are very common.
Plot, voice, humor, structure, generalized elements of a story, you can be inspired by all of these from another author. For an original work, avoid using the parts of another modern work that can be copyrighted: specific characters, unique settings, illustrations, the writing itself (not an exhaustive list). Literature has a somewhat more flexible tradition on using ideas for your own compared to, say, academic work: most stories are ones we’ve told for thousands of years, and will continue to tell.