It depends. In most of the cases, the aircraft have been instrumented and pushed so much that it not possible to modify them for commercial flight. In these cases, they are either preserved or continued to be used as test aircraft. In other cases, the aircraft are modified and delivered.
Boeing 747- The first ever Boeing 747 was used exclusively as a test aircraft and was later handed over to museum. On the other hand all the 747-8s were converted back after test flights and delivered to customers.
Boeing 777- The first 777s were considered production models, not prototypes and were delivered to customers after testing.
Boeing 787- It is kind of a mixed bag here- The first three 787s are in museums across the world (two in the US, on eone in Japan). Boeing is still using one as a testbed, while one more is in storage. Another aircraft used for testing was later modified and sold to the Mexican Air Force.
Airbus A350XWB- Right now, Airbus is holding all the five testing aircraft and using them for testing or demostrationdemonstration flights.
Airbus A380- Airbus has all the test aircraft.
You can check out the production lists of various aircraft here