By chance do you have a book by Ron Wodaski The New CCD Astronomy, on imagaing? If not a really good book to get your started.
Dark frames are used to to subtract out the noise from the sub frames/ different temps and exposure times will exhibit different amounts of noise and in different places
Flats are used to subtract out dust, finger prints, anything that might be on the lens/filters/ or camera for that matter.