Is there any IC which converts 230V AC to 5V DC? As lossless as possible. I want to connect my microcontroller to an ordinary electrical socket and I don't have enough space available. Thanks.
There's no such thing as "lossless" anything in electronics, and there's not a single IC that's designed to do what you want. But here are some different supply ideas. Since you didn't specify current consumption or efficiency, let's look at three different approaches:

Non-isolating Zener supply

5% efficiency or less

Plug-in timers that are microcontroller-based usually use non-isolating power supplies, like this:



R1 essentially drops the difference between the Zener diode and the AC mains potential, so it's not going to be efficient for anything except light loads. Also, your load can't change dramatically, as the resistor has to be sized to provide enough current to the zener to cause it to reverse avalanche, without providing too much current. If your load starts pulling too much current, its voltage will drop. If your load doesn't pull enough current, the zener diode can be damaged. 

Pros


Very small
Very cheap
Excellent for extremely light loads (MCU + switch device)


Cons


No isolation
Load current isn't flexible; must be fixed within small window


Mains-frequency regulated transformer supply

20-75% efficiency

You can always use a transformer (60:1 or so), a bridge rectifier, and a linear regulator, like this:


This introduces a bulky, costly transformer into the design, but it's more efficient than the previous design, and your load can vary quite a bit.

Pros


Easiest to implement
Designed for medium current loads -- a clock radio, for example.
Full isolation
Relatively inexpensive


Cons


Bulky
Fairly inefficient


Fully-isolated Switch-mode AC/DC Converter

75-95% efficiency

Most efficient (and most complex) is a AC/DC switching converter. These work on the principle of first converting AC to DC, then switching the DC at very high frequencies to make optimal use of the transformer's characteristics, as well as minimize the size (and loss) of the filter network on the secondary. Power Integrations makes an IC that does all the control/feedback/driving -- all you need is to add a transformer and optoisolators. Here's an example design:


As you can see, AC mains voltage is immediately rectified and filtered to produce high voltage DC. The Power Integrations device switches this voltage rapidly across the transformer's primary side. High-frequency AC is seen on the secondary, and rectified and filtered. You'll notice that the component values are quite small, even considering the current use. This is because high-frequency AC requires much smaller components to filter than line-frequency AC. Most of these devices have special ultra-low-power modes that work quite well.

These converters, in general, provide a great amount of efficiency and can also source high-power loads. These are the sorts of supplies you see in everything from tiny cell phone chargers to laptop and desktop computer power supplies.

Pros


Extremely Efficient
Full isolation
High output current: can source 50+ amps of low voltage DC fairly easily.
Small size


Cons


Large BOM (Bill of Materials)
Difficult to design
Requires thoughtful PCB layout
Usually requires custom transformer design
Expensive

