How to deal with this pair of wires coming out of transformer?
It's a doorbell transformer. Line voltage input and probably 24 vac output. Turn off the breaker and look closely at the transformer, the specs will be on it.

You should mount it in a covered electrical box (modern ones are designed with a 1/2" threaded post to facilitate just that) so the line voltage connection is properly enclosed, rewiring where necessary to replace deficient wire and connections. I would probably replace the transformer too but it's not strictly necessary.