Usage of ExecSQL in UDF? Problem:
is it possible to use sp_executesql or EXEC inside of a user defined function?

Thanks!
Not in a T-SQL function, but executing stored procedures can be done in SQLCLR functions.

An example of using a .NET / C# SQLCLR user-defined function to execute a stored procedure is shown in the following article (which I wrote):

Stairway to SQLCLR Level 2: Sample Stored Procedure and Function