Hi.
Yes, you can install the drive from the old iMac into another same-model iMac and it should have no problem booting.
Optionally, I would suggest you search online for a FireWire external drive enclosure. Take the drive out of your old iMac and install it into the FireWire drive enclosure. Now you can use your old drive as an external, bootable hd on your replacement iMac, or on any other Mac that you might purchase in the future.
Of course, you could swap the drive from your failed iMac into the one you buy on Craig's List... then put the drive you take from that into the external drive enclosure.
I suggest a FireWire enclosure because the older iMacs, the PPC models, can boot from an external FireWire drive, but I believe not from a USB drive.