But I don't believe that just connecting input of the inverter to solar panels and output of it to the AC line would work. I think the phases of the inverter output and the public AC voltage must match each other.
Correct. But this is a very common problem, and so a constellation of products have been developed to do exactly that. They are called "Grid Tie" inverters. Not only can they sync to the grid, they must. They must not inject onto the grid when the power is down!*
The requirements for a grid-tie inverter are specified by our old friend UL (Underwriter's Laboratories, i.e. insurance underwriters) - in their UL 1741 document. There are also issues on the panel side, such as Rapid Shutdown (NEC 690.12), which the grid-tie inverter may be involved in. (makes perfect sense to Rapid Shutdown anytime the grid is down, and the grid-tie inverter is well-suited to provide that feature).
I also feel that I would need a different power-meter for my house. Because the current one is designed for one-way transfer of electricity; it may not be detecting the direction of power transfer.
Correct. If you have the wrong kind of meter, it will charge you for the power you are generating, instead of pay you. So you need to coordinate with the electric company. Naturally they will want to pay you very little for your generated power; but this is a scam.
Actually, solar panels make peaking power by nature. Peaking is the highest-demand time, when they are spinning up all the generators, even the expensive ones - the diesels and gas turbines. (partly, they're expensive because the bank wants the mortgage paid 24x7). Peaking power commands top dollar in the spot market, which is right where solar is. However most residents are flat-rate billed, i.e. at 12 cents/kwh. So even "net metering" is a sweet deal for the power company, as they are paying "average" prices for valuable peak power.
What hardware is used for this purpose? I want implement the circuits myself if I can.
No. Labors of love are worth their weight in gold. Don't waste it reinventing this wheel. A UL 1741 inverter is a very serious engineering work, akin to building your own G4 cell phone. It's a huge skill mountain to climb, mostly boring, inapplicable to other fields, and full of regulatory claptrap. Not worth it. Buy a COTS UL 1741 inverter, and spend your love on a project where innovation has a chance of being rewarded, you have a chance of finishing, and it'll actually help your resume.
* What's the matter with making AC when the grid is down? Inevitably some epsilon-minus would wire it so it's still attached to the grid, which would backfeed distribution transformers. When you backfeed a transformer, you step up voltage instead of stepping ot down. This energizes parts of the grid that are expected to be off. This is bad news for both linemen (who, in haste to restore power, often don't do full ground-out procedures), and random citizens near downed lines, which were thought to be a non-priority since they are on the dead side of the break.