There is often alot of programming code which two completely different games may have in common: both carmageddon and tetris need to be able to draw things on screen, play sound, receive input from the user, etc.
Because game companies don't want to spend development time on making these systems every single time they start a new project this code is reused.
We call it an engine because it is the code that "makes the game run" - It's actually just programming code like the rest of the game.
Because it takes alot of time and effort to make an engine there are companies that specialize in their development, other companies then use their code to run their game.
A library is a similar collection of programming code which you can "attach" to your project. The directX library is a collection of code which 'talks' to the graphics card for you - it is possible to talk to the graphics card without this library but it would be much more difficult than just saying to directx "draw this for me".
It's far easier to just use the code somebody else has already written (this is what programmers mean when they say "don't reinvent the wheel").
Think of it like this:
You're making your own car.
The body of the car is your game: you can make it look like a blue volkswagen, a green porche, anything you like.
The thing that makes the car move is the engine (hence the term) - you can make your own engine but it probably won't run as well as one you buy from the garage.
You can make your car with engine X or engine Y, that's up to you. The body of the car will look the same - it might not be as fast though.
The library would be something like a new CD player you install in the car, just a little piece of programming which is ready made for you.
You don't need to know how a CD is played - all you need to do is insert the disk and press play.