Can I use an external hdd that I'm already using with my mac as a time machine backup without erasing all the data on it?
Yes, as long as the drive is formatted in Mac OS Extended (Journaled).
Calculate how much space the backup for the iMac will take and allow at least 2-3 times to allow plenty of space for incremental backups.
So, if your iMac is 100 GB, you would need at least 200 GB for Time Machine on the drive. 300 GB would be better. Even better would be a dedicated drive just for Time Machine if at all possible.